Browse Source

Merge pull request #307 from visuddhinanda:master

Merge branch 'master' of https://github.com/visuddhinanda/mint
visuddhinanda 5 years ago
parent
commit
ef0d0fcb7b
7 changed files with 243 additions and 25 deletions
  1. 22 0
      app/admin/pali_toc.sql
  2. 1 1
      app/path.php
  3. 15 11
      app/term/term.js
  4. 19 3
      app/term/term_edit_dlg.js
  5. 30 3
      app/term/term_post.php
  6. 149 0
      app/upgrade/upgrade_pali_toc.php
  7. 7 7
      pali_title/98_title.csv

+ 22 - 0
app/admin/pali_toc.sql

@@ -0,0 +1,22 @@
+--
+-- 由SQLiteStudio v3.1.1 产生的文件 周四 2月 11 17:30:07 2021
+--
+-- 文本编码:UTF-8
+--
+PRAGMA foreign_keys = off;
+BEGIN TRANSACTION;
+
+-- 表:course
+DROP TABLE IF EXISTS course;
+CREATE TABLE course (id INTEGER PRIMARY KEY AUTOINCREMENT, book INTEGER, para INTEGER, lesson_id CHAR (36), start INTEGER, "end" INTEGER);
+
+-- 表:nissaya
+DROP TABLE IF EXISTS nissaya;
+CREATE TABLE nissaya (id INTEGER PRIMARY KEY AUTOINCREMENT, book INTEGER, para INTEGER, lang CHAR (8), media INTEGER);
+
+-- 表:progress
+DROP TABLE IF EXISTS progress;
+CREATE TABLE progress (id INTEGER PRIMARY KEY AUTOINCREMENT, book INTEGER, para INTEGER, lang CHAR (8), "all" REAL, public REAL);
+
+COMMIT TRANSACTION;
+PRAGMA foreign_keys = on;

+ 1 - 1
app/path.php

@@ -21,7 +21,7 @@ define("_FILE_DB_PALITEXT_" , __DIR__."/../tmp/appdata/palicanon/pali_text.db3")
 define("_FILE_DB_STATISTICS_" , __DIR__."/../tmp/appdata/palicanon/word_statistics.db3");
 define("_FILE_DB_PALI_SENTENCE_" , __DIR__."/../tmp/appdata/palicanon/pali_sent.db3");
 define("_FILE_DB_PALI_SENTENCE_SIM_" , __DIR__."/../tmp/appdata/palicanon/pali_sim.db3");
-//define("_FILE_DB_PALI_SENTENCE_SIM_" , __DIR__."/../tmp/appdata/palicanon/pali_sent_sim.db3");
+define("_FILE_DB_PALI_TOC_" , __DIR__."/../tmp/appdata/palicanon/pali_toc.db3");
 define("_FILE_DB_INDEX_"  , __DIR__."/../tmp/appdata/palicanon/index.db3");
 define("_FILE_DB_WORD_INDEX_"  , __DIR__."/../tmp/appdata/palicanon/wordindex.db3");
 define("_FILE_DB_PALI_INDEX_"  , __DIR__."/../tmp/appdata/palicanon/paliindex.db3");

+ 15 - 11
app/term/term.js

@@ -670,17 +670,21 @@ function term_updata_translation() {
 
 function term_show_win(guid, keyWord = "") {
 	if (guid == "") {
-		$(term_body).html(
-			"“" +
-				keyWord +
-				"”" +
-				gLocal.gui.no_created +
-				"<br /><button onclick=\"term_add_new('" +
-				keyWord +
-				"')\">" +
-				gLocal.gui.create_now +
-				"</button>"
-		);
+		if (typeof term_body == "undefined") {
+			term_edit_dlg_open("", keyWord);
+		} else {
+			$(term_body).html(
+				"“" +
+					keyWord +
+					"”" +
+					gLocal.gui.no_created +
+					"<br /><button onclick=\"term_add_new('" +
+					keyWord +
+					"')\">" +
+					gLocal.gui.create_now +
+					"</button>"
+			);
+		}
 	} else {
 		let currWord = term_lookup_my_id(guid);
 		if (currWord) {

+ 19 - 3
app/term/term_edit_dlg.js

@@ -21,8 +21,19 @@ function term_edit_dlg_init(title = gLocal.gui.dict_terms) {
 		],
 	});
 }
-function term_edit_dlg_open(id = "") {
+function term_edit_dlg_open(id = "", word = "") {
 	if (id == "") {
+		let newWord = new Object();
+		newWord.guid = "";
+		newWord.word = word;
+		newWord.meaning = "";
+		newWord.other_meaning = "";
+		newWord.tag = "";
+		newWord.note = "";
+		newWord.language = "zh";
+		newWord.channal = "";
+		let html = term_edit_dlg_render(newWord);
+		$("#term_edit_dlg_content").html(html);
 		$("#term_edit_dlg").dialog("open");
 	} else {
 		$.post(
@@ -43,7 +54,12 @@ function term_edit_dlg_open(id = "") {
 function term_edit_dlg_render(word = "") {
 	if (word == "") {
 		word = new Object();
-		word.pali = "";
+		word.guid = "";
+		word.word = pali;
+		word.meaning = "";
+		word.other_meaning = "";
+		word.tag = "";
+		word.note = "";
 	}
 	let output = "";
 	output += "<form action='##' id='form_term'>";
@@ -71,7 +87,7 @@ function term_edit_dlg_render(word = "") {
 	output += "<fieldset>";
 	output += "<legend>" + gLocal.gui.other_meaning + "</legend>";
 	output +=
-		"<input type='input' id='term_edit_form_othermeaning name='mean2' value='" +
+		"<input type='input' id='term_edit_form_othermeaning' name='mean2' value='" +
 		word.other_meaning +
 		"' placeholder=" +
 		gLocal.gui.optional +

+ 30 - 3
app/term/term_post.php

@@ -7,6 +7,7 @@ $respond=array("status"=>0,"message"=>"");
 PDO_Connect("sqlite:"._FILE_DB_TERM_);
 
 if($_POST["id"]!=""){
+	#更新
     $query="UPDATE term SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? ,  language = ? , note = ? , receive_time= ?, modify_time= ?   where guid= ? ";
     $stmt = @PDO_Execute($query,array($_POST["mean"],
                                         $_POST["mean2"],
@@ -17,7 +18,7 @@ if($_POST["id"]!=""){
                                         mTime(),
                                         mTime(),
                                         $_POST["id"]
-                                                            ));
+                                        ));
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
         $error = PDO_ErrorInfo();
         $respond['status']=1;
@@ -26,10 +27,36 @@ if($_POST["id"]!=""){
     else{
         $respond['status']=0;
         $respond['message']=$_POST["word"];
-    }		
+    }
 }
 else{
-
+	#新建
+	$parm[]=UUID::v4();
+	$parm[]=$_POST["word"];
+	$parm[]=pali2english($_POST["word"]);
+	$parm[]=$_POST["mean"];
+	$parm[]=$_POST["mean2"];
+	$parm[]=$_POST["tag"];
+	$parm[]=$_POST["channal"];
+	$parm[]=$_POST["language"];
+	$parm[]=$_POST["note"];
+	$parm[]=$_COOKIE["userid"];
+	$parm[]=0;
+	$parm[]=mTime();
+	$parm[]=mTime();
+	$parm[]=mTime();
+	$query="INSERT INTO term (id, guid, word, word_en, meaning, other_meaning, tag, channal, language,note,owner,hit,create_time,modify_time,receive_time ) 
+	VALUES (NULL, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "; 
+	$stmt = @PDO_Execute($query,$parm);
+    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+        $error = PDO_ErrorInfo();
+        $respond['status']=1;
+        $respond['message']=$error[2].$query;
+    }
+    else{
+        $respond['status']=0;
+        $respond['message']=$_POST["word"];
+    }
 }
     
 

+ 149 - 0
app/upgrade/upgrade_pali_toc.php

@@ -0,0 +1,149 @@
+<?php
+#升级段落完成度数据库
+require_once '../path.php';
+
+
+$dns = "sqlite:"._FILE_DB_PALI_TOC_;
+$dbh_toc = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+$dbh_toc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
+
+$dns = "sqlite:"._FILE_DB_SENTENCE_;
+$dbh_sent = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+$dbh_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+
+$dns = "sqlite:"._FILE_DB_PALI_SENTENCE_;
+$dbh_pali_sent = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+$dbh_pali_sent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+
+$dns = "sqlite:"._FILE_DB_PALITEXT_;
+$dbh_pali_text = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+$dbh_pali_text->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+$valid_book = array();
+
+#第一步 查询有多少书有译文
+$query = "SELECT book from sentence where strlen>0 and begin<>''  and language<>'' and book <1000  group by book";
+$stmt = $dbh_sent->prepare($query);
+$stmt->execute();
+$valid_book = $stmt->fetchAll(PDO::FETCH_ASSOC);
+echo "book:".count($valid_book)."<br>\n";
+
+#第一步 查询语言
+$query = "SELECT language from sentence where strlen>0 and begin<>''  and language<>'' and book <1000   group by language";
+$stmt = $dbh_sent->prepare($query);
+$stmt->execute();
+$result_lang = $stmt->fetchAll(PDO::FETCH_ASSOC);
+echo "lang:".count($result_lang)."<br>\n";
+
+$query = "DELETE FROM progress WHERE 1";
+$sth_toc = $dbh_toc->prepare($query);
+$sth_toc->execute();
+$query = "DELETE FROM progress_chapter WHERE 1";
+$sth_toc = $dbh_toc->prepare($query);
+$sth_toc->execute();
+
+/* 开始一个事务,关闭自动提交 */
+$dbh_toc->beginTransaction();
+$query = "INSERT INTO progress (book, para , lang , all_strlen,public_strlen) VALUES (?, ?, ? , ? ,? )";
+$sth_toc = $dbh_toc->prepare($query);
+foreach ($result_lang as $lang) {
+	# 第二步 生成para progress 1,2,15,zh-tw
+	
+	#查询该语言有多少段
+	$query = "select book,paragraph from sentence where strlen>0 and language= ? and book<1000 group by book,paragraph";
+	$stmt = $dbh_sent->prepare($query);
+	$stmt->execute(array($lang["language"]));
+	$result_para = $stmt->fetchAll(PDO::FETCH_ASSOC);
+	foreach ($result_para as $para) {
+		
+		# 查询每个段落的等效巴利语字符数
+		$query = "select begin from sentence where strlen>0 and language= ? and book = ? and paragraph = ? and begin<>'' group by begin,end";
+		$stmt = $dbh_sent->prepare($query);
+		$stmt->execute(array($lang["language"],$para["book"],$para["paragraph"]));
+		$result_sent = $stmt->fetchAll(PDO::FETCH_ASSOC);
+		if(count($result_sent)>0){
+			echo "book:{$para["book"]} para: {$para["paragraph"]}\n";
+			#查询这些句子的总共等效巴利语字符数
+			$place_holders = implode(',', array_fill(0, count($result_sent), '?'));
+			$query = "select sum(length) as strlen from pali_sent where book = ? and paragraph = ? and begin in ($place_holders)";
+			$sth = $dbh_pali_sent->prepare($query);
+			$param = array();
+			$param[] = $para["book"];
+			$param[] = $para["paragraph"];
+			foreach ($result_sent as $sent) {
+				# code...
+				$param[] = (int)$sent["begin"];
+			}
+			$sth->execute($param);
+			$result_strlen = $sth->fetch(PDO::FETCH_ASSOC);
+			if($result_strlen){
+				$para_strlen = $result_strlen["strlen"];
+			}
+			else{
+				$para_strlen = 0;
+			}
+			$sth_toc->execute(array($para["book"],$para["paragraph"],$lang["language"],$para_strlen,0));
+		}
+	}
+
+}
+$dbh_toc->commit();
+if (!$sth_toc || ($sth_toc && $sth_toc->errorCode() != 0)) {
+	/*  识别错误且回滚更改  */
+	$sth_toc->rollBack();
+	$error = $dbh_toc->errorInfo();
+	echo "error:".$error[2]."\n";
+}
+
+#第三步生成 段落完成度库
+/* 开始一个事务,关闭自动提交 */
+$dbh_toc->beginTransaction();
+$query = "INSERT INTO progress_chapter (book, para , lang , all_trans,public) VALUES (?, ?, ? , ? ,? )";
+$sth_toc = $dbh_toc->prepare($query);
+
+foreach ($valid_book as $key => $book) {
+	echo "doing chapter in book ".$book["book"] ."\n";
+	# code...
+	$query = "SELECT paragraph , chapter_len from pali_text where level < 8 and book = ?";
+	$stmt = $dbh_pali_text->prepare($query);
+	$stmt->execute(array($book["book"]));
+	$result_chapter = $stmt->fetchAll(PDO::FETCH_ASSOC);
+	foreach ($result_chapter as $key => $chapter) {
+		# 查询巴利字符数
+		$query = "SELECT sum(strlen) as pali_strlen from pali_sent_index where book = ? and para between ? and ? ";
+		$stmt = $dbh_pali_sent->prepare($query);
+		$stmt->execute(array($book["book"],$chapter["paragraph"],$chapter["paragraph"]+$chapter["chapter_len"]));
+		$result_chapter_strlen = $stmt->fetch(PDO::FETCH_ASSOC);
+		if($result_chapter_strlen){
+			$pali_strlen = (int)$result_chapter_strlen["pali_strlen"];
+			# 译文等效字符数
+			foreach ($result_lang as $lang) {
+				$query = "SELECT sum(all_strlen) as all_strlen from progress where book = ? and (para between ? and ? )and lang = ?";
+				$stmt = $dbh_toc->prepare($query);
+				$stmt->execute(array($book["book"],$chapter["paragraph"],$chapter["paragraph"]+$chapter["chapter_len"],$lang["language"]));
+				$result_chapter_trans_strlen = $stmt->fetch(PDO::FETCH_ASSOC);
+				if($result_chapter_trans_strlen){
+					$tran_strlen = (int)$result_chapter_trans_strlen["all_strlen"];
+					if($tran_strlen>0){
+						$progress = $tran_strlen/$pali_strlen;
+						$sth_toc->execute(array($book["book"],$chapter["paragraph"],$lang["language"],$progress,0));
+						//echo "{$book["book"]},{$chapter["paragraph"]},{$lang["language"]},{$progress}\n";
+					}
+
+				}
+				#插入段落数据
+			}			
+		}
+	}
+}
+$dbh_toc->commit();
+if (!$sth_toc || ($sth_toc && $sth_toc->errorCode() != 0)) {
+	/*  识别错误且回滚更改  */
+	$sth_toc->rollBack();
+	$error = $dbh_toc->errorInfo();
+	echo "error:".$error[2]."\n";
+}
+
+?>

File diff suppressed because it is too large
+ 7 - 7
pali_title/98_title.csv


Some files were not shown because too many files changed in this diff