/src/java/com/me/helper/TourHelper.java

https://gitlab.com/yzrhy/ServerRecommenderSystem · Java · 1255 lines · 920 code · 170 blank · 165 comment · 151 complexity · b2cc053962b4f955b50ffceb241e09c9 MD5 · raw file

  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package com.me.helper;
  7. import com.me.dbo.MyConnection;
  8. import com.me.dbo.TourDBO;
  9. import static com.me.dbo.TourDBO.PARENTS;
  10. import com.me.model.TourSite;
  11. import java.sql.Connection;
  12. import java.util.ArrayList;
  13. import java.util.Arrays;
  14. import java.util.Collections;
  15. import java.util.Comparator;
  16. import java.util.HashMap;
  17. import java.util.LinkedHashMap;
  18. import java.util.LinkedList;
  19. import java.util.List;
  20. import java.util.Map;
  21. import java.util.Iterator;
  22. import java.util.TreeMap;
  23. /**
  24. *
  25. * @author yizrahya
  26. */
  27. public class TourHelper {
  28. public HashMap<String, Integer> cache = new HashMap<String, Integer>();
  29. public HashMap<String, Integer> cache2 = new HashMap<String, Integer>();
  30. public HashMap<String, Integer> cache3 = new HashMap<String, Integer>();
  31. public HashMap<String, Integer> cache4 = new HashMap<String, Integer>();
  32. public HashMap<String, Integer> cache5 = new HashMap<String, Integer>();
  33. public boolean isOtherWilayah;
  34. public boolean isIsOtherWilayah() {
  35. return isOtherWilayah;
  36. }
  37. public void setIsOtherWilayah(boolean isOtherWilayah) {
  38. this.isOtherWilayah = isOtherWilayah;
  39. }
  40. public static final String[] PARENTS = new String[] {"wisata bahari","wisata alam","eko wisata","wisata buatan", "wisata sejarah & budaya", "wisata religi", "wisata belanja", "wisata kuliner", "agrowisata"};
  41. public ArrayList<TourSite> getSites(ArrayList<String> keywords, int idWilayah, int budgets){
  42. TourDBO tdbo = new TourDBO();
  43. ArrayList<String> sitesNames = new ArrayList<>();
  44. ArrayList<String> topSitesNames = new ArrayList<>();
  45. ArrayList<TourSite> topSites = new ArrayList();
  46. int inputCount = keywords.size();
  47. int match = 0;
  48. int percentage = 0;
  49. HashMap<String, Integer> sortedMap = new HashMap<String, Integer>();
  50. String result = "";
  51. // this.setIsOtherWilayah(false);
  52. for(String keyword : keywords){
  53. System.out.println(keyword);
  54. sitesNames = tdbo.GetSitesName(keyword, idWilayah, budgets);
  55. System.out.println("sitname" + sitesNames);
  56. for(String siteName : sitesNames)
  57. {
  58. System.out.println(siteName);
  59. boolean isNew = cache.get(siteName) == null;
  60. System.out.println("sitename: " + siteName);
  61. // System.out.println("isNew :" + isNew);
  62. if(isNew)
  63. {
  64. // System.out.println("new key:" + siteName);
  65. cache.put(siteName, 1);
  66. }
  67. else
  68. {
  69. int siteValue = cache.get(siteName).intValue();
  70. cache.put(siteName,siteValue+1);
  71. // System.out.println("KEYY:" + siteName +" new valuee : "+cache.get(siteName));
  72. }
  73. }
  74. tdbo.insertKeywordHistory(keyword);
  75. }
  76. // cache.isEmpty() = true;
  77. if(!cache.isEmpty()){
  78. // sitesNames = tdbo.GetSitesName(keyword, 0, 0);
  79. // this.setIsOtherWilayah(true);
  80. for(String keyword : keywords){
  81. sitesNames = tdbo.GetSitesName(keyword, 0, 0);
  82. for(String siteName : sitesNames)
  83. {
  84. System.out.println(siteName);
  85. boolean isNew = cache.get(siteName) == null;
  86. System.out.println("sitename: " + siteName);
  87. // System.out.println("isNew :" + isNew);
  88. if(isNew)
  89. {
  90. // System.out.println("new key:" + siteName);
  91. cache.put(siteName, 1);
  92. }
  93. else
  94. {
  95. int siteValue = cache.get(siteName).intValue();
  96. cache.put(siteName,siteValue+1);
  97. // System.out.println("KEYY:" + siteName +" new valuee : "+cache.get(siteName));
  98. }
  99. }
  100. }
  101. }
  102. Iterator iterator = cache.keySet().iterator();
  103. String maxKey = "";
  104. int maxValue = 0;
  105. ArrayList<String> survivedKey = new ArrayList<>();
  106. while (iterator.hasNext()) {
  107. String key = iterator.next().toString();
  108. int value = cache.get(key);
  109. // percentage = ((value*100)/inputCount);
  110. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  111. System.out.println("valll" + value);
  112. // System.out.println("inputcount " + inputCount);
  113. // System.out.println("persentaseeee" + percentage);
  114. if(value > maxValue)
  115. {
  116. System.out.println("value lebih besar dari max curr");
  117. maxValue = value;
  118. maxKey = key;
  119. }
  120. }
  121. boolean xx = true;
  122. Iterator iterator2 = cache.keySet().iterator();
  123. while (iterator2.hasNext()) {
  124. String key = iterator2.next().toString();
  125. int value = cache.get(key);
  126. percentage = ((value*100)/inputCount);
  127. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  128. System.out.println("persentaseeee" + percentage);
  129. // System.out.println("currKey:"+key +"=== currVal: "+value);
  130. if( percentage >= 60)
  131. {
  132. System.out.println("masuk");
  133. System.out.println("xxxx" + xx);
  134. if (xx)
  135. {
  136. System.out.println("update point for " + key);
  137. tdbo.updateSitePoint(key);
  138. }
  139. tdbo.InsertHistory(key);
  140. xx = false;
  141. // System.out.println("max valueeee = "+ maxValue);
  142. // System.out.println("value sama besar dengan max value, add kedalam list");
  143. survivedKey.add(key);
  144. }
  145. }
  146. for (int i = 0; i < survivedKey.size(); i++) {
  147. System.out.println("TOP HITS !!! "+survivedKey.get(i));
  148. }
  149. result = maxKey;
  150. System.out.println("maxk "+maxKey+" maxv "+maxValue);
  151. if(survivedKey.size() == 0){
  152. topSites = null;
  153. }else{
  154. topSites = tdbo.TopSites(survivedKey, idWilayah, budgets);
  155. tdbo.insertTopRecomendations(topSites.get(0));
  156. }
  157. //insert to comment history
  158. return topSites;
  159. }
  160. public ArrayList<TourSite> getRelatedSites(ArrayList<String> keywords, int idWilayah, int budgets){
  161. TourDBO tdbo = new TourDBO();
  162. ArrayList<String> sitesNames = new ArrayList<>();
  163. ArrayList<String> topSitesNames = new ArrayList<>();
  164. ArrayList<TourSite> topSites = new ArrayList();
  165. int inputCount = keywords.size();
  166. int match = 0;
  167. int percentage = 0;
  168. int threshold = tdbo.getThreshold();
  169. HashMap<String, Integer> sortedMap = new HashMap<String, Integer>();
  170. String result = "";
  171. for(String keyword : keywords){
  172. System.out.println(keyword);
  173. sitesNames = tdbo.GetSitesName(keyword, idWilayah, budgets);
  174. System.out.println("sitname" + sitesNames);
  175. for(String siteName : sitesNames)
  176. {
  177. System.out.println(siteName);
  178. boolean isNew = cache2.get(siteName) == null;
  179. System.out.println("sitename: " + siteName);
  180. // System.out.println("isNew :" + isNew);
  181. if(isNew)
  182. {
  183. // System.out.println("new key:" + siteName);
  184. cache2.put(siteName, 1);
  185. }
  186. else
  187. {
  188. int siteValue = cache2.get(siteName).intValue();
  189. cache2.put(siteName,siteValue+1);
  190. // System.out.println("KEYY:" + siteName +" new valuee : "+cache2.get(siteName));
  191. }
  192. }
  193. // tdbo.insertKeywordHistory(keyword);
  194. }
  195. if(cache2.isEmpty()){
  196. // sitesNames = tdbo.GetSitesName(keyword, 0, 0);
  197. for(String keyword : keywords){
  198. sitesNames = tdbo.GetSitesName(keyword, 0, 0);
  199. for(String siteName : sitesNames)
  200. {
  201. System.out.println(siteName);
  202. boolean isNew = cache2.get(siteName) == null;
  203. System.out.println("sitename: " + siteName);
  204. // System.out.println("isNew :" + isNew);
  205. if(isNew)
  206. {
  207. // System.out.println("new key:" + siteName);
  208. cache2.put(siteName, 1);
  209. }
  210. else
  211. {
  212. int siteValue = cache2.get(siteName).intValue();
  213. cache2.put(siteName,siteValue+1);
  214. // System.out.println("KEYY:" + siteName +" new valuee : "+cache2.get(siteName));
  215. }
  216. }
  217. }
  218. }
  219. Iterator iterator = cache2.keySet().iterator();
  220. String maxKey = "";
  221. int maxValue = 0;
  222. ArrayList<String> survivedKey = new ArrayList<>();
  223. while (iterator.hasNext()) {
  224. String key = iterator.next().toString();
  225. int value = cache2.get(key);
  226. // percentage = ((value*100)/inputCount);
  227. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  228. System.out.println("valll" + value);
  229. // System.out.println("inputcount " + inputCount);
  230. // System.out.println("persentaseeee" + percentage);
  231. if(value > maxValue)
  232. {
  233. System.out.println("value lebih besar dari max curr");
  234. maxValue = value;
  235. maxKey = key;
  236. }
  237. }
  238. boolean xx = true;
  239. Iterator iterator2 = cache2.keySet().iterator();
  240. while (iterator2.hasNext()) {
  241. String key = iterator2.next().toString();
  242. int value = cache2.get(key);
  243. percentage = ((value*100)/inputCount);
  244. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  245. System.out.println("persentaseeee" + percentage);
  246. // System.out.println("currKey:"+key +"=== currVal: "+value);
  247. if( percentage < threshold)
  248. {
  249. System.out.println("masuk");
  250. System.out.println("xxxx" + xx);
  251. if (xx)
  252. {
  253. System.out.println("update point for " + key);
  254. // tdbo.updateSitePoint(key);
  255. }
  256. tdbo.InsertHistory(key);
  257. xx = false;
  258. // System.out.println("max valueeee = "+ maxValue);
  259. // System.out.println("value sama besar dengan max value, add kedalam list");
  260. survivedKey.add(key);
  261. }
  262. }
  263. for (int i = 0; i < survivedKey.size(); i++) {
  264. System.out.println("TOP HITS !!! "+survivedKey.get(i));
  265. }
  266. result = maxKey;
  267. System.out.println("maxk "+maxKey+" maxv "+maxValue);
  268. if(survivedKey.size() == 0){
  269. topSites = null;
  270. }else{
  271. topSites = tdbo.TopSites(survivedKey, idWilayah, budgets);
  272. tdbo.insertTopRecomendations(topSites.get(0));
  273. }
  274. // for()
  275. //insert to comment history
  276. return topSites;
  277. }
  278. public TourSite getSiteDetail(String siteName)
  279. {
  280. TourDBO tdbo = new TourDBO();
  281. TourSite tourSite = tdbo.GetSiteDetails(siteName);
  282. return tourSite;
  283. }
  284. public ArrayList<TourSite> getSites2(ArrayList<String> keywords, int idWilayah, int budgets){
  285. TourDBO tdbo = new TourDBO();
  286. ArrayList<String> sitesNames = new ArrayList<>();
  287. ArrayList<String> topSitesNames = new ArrayList<>();
  288. ArrayList<TourSite> topSites = new ArrayList();
  289. int inputCount = keywords.size();
  290. int match = 0;
  291. int percentage = 0;
  292. HashMap<String, Integer> sortedMap = new HashMap<String, Integer>();
  293. String result = "";
  294. sitesNames = tdbo.GetSitesName2(keywords, idWilayah, budgets);
  295. System.out.println("sitname" + sitesNames);
  296. for(String siteName : sitesNames)
  297. {
  298. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  299. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  300. int occurence = 0;
  301. for(String word : itemsKey){
  302. // occurence = 0;
  303. for(String wordCompare : keywords){
  304. if(word.equalsIgnoreCase(wordCompare)){
  305. occurence ++;
  306. }
  307. }
  308. }
  309. cache.put(siteName, occurence);
  310. }
  311. // tdbo.insertKeywordHistory(keyword);
  312. if(cache.isEmpty()){
  313. // sitesNames = tdbo.GetSitesName(keyword, 0, 0);
  314. for(String keyword : keywords){
  315. sitesNames = tdbo.GetSitesName2(keywords, 0, 0);
  316. for(String siteName : sitesNames)
  317. {
  318. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  319. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  320. int occurence = 0;
  321. for(String word : itemsKey){
  322. // occurence = 0;
  323. for(String wordCompare : keywords){
  324. if(word.equalsIgnoreCase(wordCompare)){
  325. occurence ++;
  326. }
  327. }
  328. }
  329. cache.put(siteName, occurence);
  330. }
  331. }
  332. }
  333. Iterator iterator = cache.keySet().iterator();
  334. String maxKey = "";
  335. int maxValue = 0;
  336. ArrayList<String> survivedKey = new ArrayList<>();
  337. while (iterator.hasNext()) {
  338. String key = iterator.next().toString();
  339. int value = cache.get(key);
  340. // percentage = ((value*100)/inputCount);
  341. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  342. System.out.println("valll" + value);
  343. // System.out.println("inputcount " + inputCount);
  344. // System.out.println("persentaseeee" + percentage);
  345. if(value > maxValue)
  346. {
  347. System.out.println("value lebih besar dari max curr");
  348. maxValue = value;
  349. maxKey = key;
  350. }
  351. }
  352. boolean xx = true;
  353. Iterator iterator2 = cache.keySet().iterator();
  354. while (iterator2.hasNext()) {
  355. String key = iterator2.next().toString();
  356. int value = cache.get(key);
  357. percentage = ((value*100)/inputCount);
  358. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  359. System.out.println("persentaseeee" + percentage);
  360. // System.out.println("currKey:"+key +"=== currVal: "+value);
  361. int threshold = tdbo.getThreshold();
  362. if( percentage >= threshold)
  363. {
  364. System.out.println("masuk");
  365. System.out.println("xxxx" + xx);
  366. if (xx)
  367. {
  368. System.out.println("update point for " + key);
  369. tdbo.updateSitePoint(key);
  370. }
  371. tdbo.InsertHistory(key);
  372. xx = false;
  373. // System.out.println("max valueeee = "+ maxValue);
  374. // System.out.println("value sama besar dengan max value, add kedalam list");
  375. survivedKey.add(key);
  376. }
  377. }
  378. for (int i = 0; i < survivedKey.size(); i++) {
  379. System.out.println("TOP HITS !!! "+survivedKey.get(i));
  380. }
  381. result = maxKey;
  382. System.out.println("maxk "+maxKey+" maxv "+maxValue);
  383. if(survivedKey.size() == 0){
  384. topSites = null;
  385. }else{
  386. topSites = tdbo.TopSites(survivedKey, idWilayah, budgets);
  387. tdbo.insertTopRecomendations(topSites.get(0));
  388. }
  389. //insert to comment history
  390. return topSites;
  391. }
  392. public ArrayList<TourSite> getRelatedSites2(ArrayList<String> keywords, int idWilayah, int budgets){
  393. TourDBO tdbo = new TourDBO();
  394. ArrayList<String> sitesNames = new ArrayList<>();
  395. ArrayList<String> topSitesNames = new ArrayList<>();
  396. ArrayList<TourSite> topSites = new ArrayList();
  397. int inputCount = keywords.size();
  398. int match = 0;
  399. int percentage = 0;
  400. HashMap<String, Integer> sortedMap = new HashMap<String, Integer>();
  401. String result = "";
  402. // keywords = null;
  403. // for(String newKey : keywords){
  404. // boolean isParent = Arrays.asList(PARENTS).contains(newKey);
  405. //
  406. // }
  407. sitesNames = tdbo.GetSitesName2(keywords, idWilayah, budgets);
  408. System.out.println("sitname" + sitesNames);
  409. for(String siteName : sitesNames)
  410. {
  411. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  412. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  413. int occurence = 0;
  414. for(String word : itemsKey){
  415. // occurence = 0;
  416. for(String wordCompare : keywords){
  417. if(word.equalsIgnoreCase(wordCompare)){
  418. occurence ++;
  419. }
  420. }
  421. }
  422. cache.put(siteName, occurence);
  423. }
  424. // tdbo.insertKeywordHistory(keyword);
  425. if(cache.isEmpty()){
  426. // sitesNames = tdbo.GetSitesName(keyword, 0, 0);
  427. for(String keyword : keywords){
  428. sitesNames = tdbo.GetSitesName2(keywords, 0, 0);
  429. for(String siteName : sitesNames)
  430. {
  431. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  432. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  433. int occurence = 0;
  434. for(String word : itemsKey){
  435. // occurence = 0;
  436. for(String wordCompare : keywords){
  437. if(word.equalsIgnoreCase(wordCompare)){
  438. occurence ++;
  439. }
  440. }
  441. }
  442. cache.put(siteName, occurence);
  443. }
  444. tdbo.insertKeywordHistory(keyword);
  445. }
  446. }
  447. Iterator iterator = cache.keySet().iterator();
  448. String maxKey = "";
  449. int maxValue = 0;
  450. ArrayList<String> survivedKey = new ArrayList<>();
  451. while (iterator.hasNext()) {
  452. String key = iterator.next().toString();
  453. int value = cache.get(key);
  454. // percentage = ((value*100)/inputCount);
  455. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  456. System.out.println("valll" + value);
  457. // System.out.println("inputcount " + inputCount);
  458. // System.out.println("persentaseeee" + percentage);
  459. if(value > maxValue)
  460. {
  461. System.out.println("value lebih besar dari max curr");
  462. maxValue = value;
  463. maxKey = key;
  464. }
  465. }
  466. boolean xx = true;
  467. Iterator iterator2 = cache.keySet().iterator();
  468. while (iterator2.hasNext()) {
  469. String key = iterator2.next().toString();
  470. int value = cache.get(key);
  471. percentage = ((value*100)/inputCount);
  472. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  473. System.out.println("persentaseeee" + percentage);
  474. // System.out.println("currKey:"+key +"=== currVal: "+value);
  475. int threshold = tdbo.getThreshold();
  476. if( percentage < threshold )
  477. {
  478. System.out.println("masuk");
  479. System.out.println("xxxx" + xx);
  480. if (xx)
  481. {
  482. System.out.println("update point for " + key);
  483. tdbo.updateSitePoint(key);
  484. }
  485. tdbo.InsertHistory(key);
  486. xx = false;
  487. // System.out.println("max valueeee = "+ maxValue);
  488. // System.out.println("value sama besar dengan max value, add kedalam list");
  489. survivedKey.add(key);
  490. }
  491. }
  492. for (int i = 0; i < survivedKey.size(); i++) {
  493. System.out.println("TOP HITS !!! "+survivedKey.get(i));
  494. }
  495. result = maxKey;
  496. System.out.println("maxk "+maxKey+" maxv "+maxValue);
  497. if(survivedKey.size() == 0){
  498. topSites = null;
  499. }else{
  500. topSites = tdbo.TopSites(survivedKey, idWilayah, budgets);
  501. tdbo.insertTopRecomendations(topSites.get(0));
  502. }
  503. //insert to comment history
  504. return topSites;
  505. }
  506. public ArrayList<TourSite> getSitesAnd(ArrayList<String> keywords, int idWilayah, int budgets){
  507. TourDBO tdbo = new TourDBO();
  508. ArrayList<String> sitesNames = new ArrayList<>();
  509. ArrayList<String> topSitesNames = new ArrayList<>();
  510. ArrayList<TourSite> topSites = new ArrayList();
  511. int inputCount = keywords.size();
  512. int match = 0;
  513. int percentage = 0;
  514. HashMap<String, Integer> sortedMap = new HashMap<String, Integer>();
  515. String result = "";
  516. sitesNames = tdbo.GetSiteNameWAnd(keywords, idWilayah, budgets);
  517. System.out.println("sitname" + sitesNames);
  518. for(String siteName : sitesNames)
  519. {
  520. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  521. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  522. int occurence = 0;
  523. for(String word : itemsKey){
  524. // occurence = 0;
  525. for(String wordCompare : keywords){
  526. if(word.equalsIgnoreCase(wordCompare)){
  527. occurence ++;
  528. }
  529. }
  530. }
  531. cache3.put(siteName, occurence);
  532. }
  533. // tdbo.insertKeywordHistory(keyword);
  534. if(cache3.isEmpty()){
  535. // sitesNames = tdbo.GetSitesName(keyword, 0, 0);
  536. for(String keyword : keywords){
  537. sitesNames = tdbo.GetSiteNameWAnd(keywords, 0, 0);
  538. for(String siteName : sitesNames)
  539. {
  540. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  541. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  542. int occurence = 0;
  543. for(String word : itemsKey){
  544. // occurence = 0;
  545. for(String wordCompare : keywords){
  546. if(word.equalsIgnoreCase(wordCompare)){
  547. occurence ++;
  548. }
  549. }
  550. }
  551. cache3.put(siteName, occurence);
  552. }
  553. }
  554. }
  555. Iterator iterator = cache3.keySet().iterator();
  556. String maxKey = "";
  557. int maxValue = 0;
  558. ArrayList<String> survivedKey = new ArrayList<>();
  559. while (iterator.hasNext()) {
  560. String key = iterator.next().toString();
  561. int value = cache3.get(key);
  562. // percentage = ((value*100)/inputCount);
  563. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  564. System.out.println("valll" + value);
  565. // System.out.println("inputcount " + inputCount);
  566. // System.out.println("persentaseeee" + percentage);
  567. if(value > maxValue)
  568. {
  569. System.out.println("value lebih besar dari max curr");
  570. maxValue = value;
  571. maxKey = key;
  572. }
  573. }
  574. boolean xx = true;
  575. Iterator iterator2 = cache3.keySet().iterator();
  576. while (iterator2.hasNext()) {
  577. String key = iterator2.next().toString();
  578. int value = cache3.get(key);
  579. percentage = ((value*100)/inputCount);
  580. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  581. System.out.println("persentaseeee" + percentage);
  582. // System.out.println("currKey:"+key +"=== currVal: "+value);
  583. int threshold = tdbo.getThreshold();
  584. if( percentage >= threshold)
  585. {
  586. System.out.println("masuk");
  587. System.out.println("xxxx" + xx);
  588. if (xx)
  589. {
  590. System.out.println("update point for " + key);
  591. tdbo.updateSitePoint(key);
  592. }
  593. tdbo.InsertHistory(key);
  594. xx = false;
  595. // System.out.println("max valueeee = "+ maxValue);
  596. // System.out.println("value sama besar dengan max value, add kedalam list");
  597. survivedKey.add(key);
  598. }
  599. }
  600. for (int i = 0; i < survivedKey.size(); i++) {
  601. System.out.println("TOP HITS !!! "+survivedKey.get(i));
  602. }
  603. result = maxKey;
  604. System.out.println("maxk "+maxKey+" maxv "+maxValue);
  605. if(survivedKey.size() == 0){
  606. topSites = null;
  607. }else{
  608. topSites = tdbo.TopSites(survivedKey, idWilayah, budgets);
  609. int times = 0;
  610. for(TourSite top : topSites){
  611. times = tdbo.GetTotalRecomTimes(top.getNama());
  612. top.setTimes(times);
  613. switch(top.getWilayah()){
  614. case "1": top.setWilayah("Bolaang Mongondouw"); break;
  615. case "2": top.setWilayah("Minahasa"); break;
  616. case "3": top.setWilayah("Sangihe"); break;
  617. case "4": top.setWilayah("Sitaro"); break;
  618. case "5": top.setWilayah("Talaud"); break;
  619. case "6": top.setWilayah("Manado"); break;
  620. case "7": top.setWilayah("Bitung"); break;
  621. case "8": top.setWilayah("Tomohon"); break;
  622. }
  623. }
  624. tdbo.insertTopRecomendations(topSites.get(0));
  625. }
  626. //insert to comment history
  627. return topSites;
  628. }
  629. public ArrayList<TourSite> getSitesAnd2(ArrayList<String> keywords, int idWilayah, int budgets, int sizeB){
  630. TourDBO tdbo = new TourDBO();
  631. ArrayList<String> sitesNames = new ArrayList<>();
  632. ArrayList<String> topSitesNames = new ArrayList<>();
  633. ArrayList<TourSite> topSites = new ArrayList();
  634. int inputCount = keywords.size();
  635. int match = 0;
  636. int percentage = 0;
  637. HashMap<String, Integer> sortedMap = new HashMap<String, Integer>();
  638. String result = "";
  639. this.setIsOtherWilayah(false);
  640. sitesNames = tdbo.GetSiteNameWAnd(keywords, idWilayah, budgets);
  641. System.out.println("sitname" + sitesNames);
  642. for(String siteName : sitesNames)
  643. {
  644. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  645. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  646. int occurence = 0;
  647. for(String word : itemsKey){
  648. // occurence = 0;
  649. for(String wordCompare : keywords){
  650. if(word.equalsIgnoreCase(wordCompare)){
  651. occurence ++;
  652. }
  653. }
  654. }
  655. cache5.put(siteName, occurence);
  656. }
  657. for(String kw : keywords){
  658. tdbo.insertKeywordHistory(kw);
  659. }
  660. if(cache5.isEmpty()){
  661. // sitesNames = tdbo.GetSitesName(keyword, 0, 0);
  662. this.setIsOtherWilayah(true);
  663. for(String keyword : keywords){
  664. sitesNames = tdbo.GetSiteNameWAnd(keywords, 0, 0);
  665. for(String siteName : sitesNames)
  666. {
  667. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  668. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  669. int occurence = 0;
  670. for(String word : itemsKey){
  671. // occurence = 0;
  672. for(String wordCompare : keywords){
  673. if(word.equalsIgnoreCase(wordCompare)){
  674. occurence ++;
  675. }
  676. }
  677. }
  678. cache5.put(siteName, occurence);
  679. }
  680. }
  681. }
  682. Iterator iterator = cache5.keySet().iterator();
  683. String maxKey = "";
  684. int maxValue = 0;
  685. ArrayList<String> survivedKey = new ArrayList<>();
  686. while (iterator.hasNext()) {
  687. String key = iterator.next().toString();
  688. int value = cache5.get(key);
  689. // percentage = ((value*100)/inputCount);
  690. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  691. System.out.println("valll" + value);
  692. // System.out.println("inputcount " + inputCount);
  693. // System.out.println("persentaseeee" + percentage);
  694. if(value > maxValue)
  695. {
  696. System.out.println("value lebih besar dari max curr");
  697. maxValue = value;
  698. maxKey = key;
  699. }
  700. }
  701. boolean xx = true;
  702. Iterator iterator2 = cache5.keySet().iterator();
  703. while (iterator2.hasNext()) {
  704. String key = iterator2.next().toString();
  705. int value = cache5.get(key);
  706. percentage = ((value*100)/sizeB);
  707. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  708. System.out.println("persentaseeee" + percentage);
  709. // System.out.println("currKey:"+key +"=== currVal: "+value);
  710. int threshold = tdbo.getThreshold();
  711. if( percentage >= threshold)
  712. {
  713. System.out.println("masuk");
  714. System.out.println("xxxx" + xx);
  715. if (xx)
  716. {
  717. System.out.println("update point for " + key);
  718. tdbo.updateSitePoint(key);
  719. }
  720. tdbo.InsertHistory(key);
  721. xx = false;
  722. // System.out.println("max valueeee = "+ maxValue);
  723. // System.out.println("value sama besar dengan max value, add kedalam list");
  724. survivedKey.add(key);
  725. }
  726. }
  727. for (int i = 0; i < survivedKey.size(); i++) {
  728. System.out.println("TOP HITS !!! "+survivedKey.get(i));
  729. }
  730. result = maxKey;
  731. System.out.println("maxk "+maxKey+" maxv "+maxValue);
  732. if(survivedKey.size() == 0){
  733. topSites = null;
  734. }else{
  735. topSites = tdbo.TopSites(survivedKey, idWilayah, budgets);
  736. int times = 0;
  737. String wil = "";
  738. for(TourSite top : topSites){
  739. times = tdbo.GetTotalRecomTimes(top.getNama());
  740. // top.setWilayah(maxKey);
  741. top.setTimes(times);
  742. switch(top.getWilayah()){
  743. case "1": top.setWilayah("Bolaang Mongondouw"); break;
  744. case "2": top.setWilayah("Minahasa"); break;
  745. case "3": top.setWilayah("Sangihe"); break;
  746. case "4": top.setWilayah("Sitaro"); break;
  747. case "5": top.setWilayah("Talaud"); break;
  748. case "6": top.setWilayah("Manado"); break;
  749. case "7": top.setWilayah("Bitung"); break;
  750. case "8": top.setWilayah("Tomohon"); break;
  751. }
  752. }
  753. tdbo.insertTopRecomendations(topSites.get(0));
  754. }
  755. //insert to comment history
  756. return topSites;
  757. }
  758. public ArrayList<TourSite> getSitesAndRel2(ArrayList<String> keywords, int idWilayah, int budgets, int sizeB){
  759. TourDBO tdbo = new TourDBO();
  760. ArrayList<String> sitesNames = new ArrayList<>();
  761. ArrayList<String> topSitesNames = new ArrayList<>();
  762. ArrayList<TourSite> topSites = new ArrayList();
  763. int inputCount = keywords.size();
  764. int match = 0;
  765. int percentage = 0;
  766. HashMap<String, Integer> sortedMap = new HashMap<String, Integer>();
  767. String result = "";
  768. this.setIsOtherWilayah(false);
  769. sitesNames = tdbo.GetSiteNameWAnd(keywords, idWilayah, budgets);
  770. System.out.println("sitname" + sitesNames);
  771. for(String siteName : sitesNames)
  772. {
  773. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  774. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  775. int occurence = 0;
  776. for(String word : itemsKey){
  777. // occurence = 0;
  778. for(String wordCompare : keywords){
  779. if(word.equalsIgnoreCase(wordCompare)){
  780. occurence ++;
  781. }
  782. }
  783. }
  784. cache5.put(siteName, occurence);
  785. }
  786. for(String kw : keywords){
  787. tdbo.insertKeywordHistory(kw);
  788. }
  789. if(cache5.isEmpty()){
  790. // sitesNames = tdbo.GetSitesName(keyword, 0, 0);
  791. this.setIsOtherWilayah(true);
  792. for(String keyword : keywords){
  793. sitesNames = tdbo.GetSiteNameWAnd(keywords, 0, 0);
  794. for(String siteName : sitesNames)
  795. {
  796. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  797. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  798. int occurence = 0;
  799. for(String word : itemsKey){
  800. // occurence = 0;
  801. for(String wordCompare : keywords){
  802. if(word.equalsIgnoreCase(wordCompare)){
  803. occurence ++;
  804. }
  805. }
  806. }
  807. cache5.put(siteName, occurence);
  808. }
  809. }
  810. }
  811. Iterator iterator = cache5.keySet().iterator();
  812. String maxKey = "";
  813. int maxValue = 0;
  814. ArrayList<String> survivedKey = new ArrayList<>();
  815. while (iterator.hasNext()) {
  816. String key = iterator.next().toString();
  817. int value = cache5.get(key);
  818. // percentage = ((value*100)/inputCount);
  819. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  820. System.out.println("valll" + value);
  821. // System.out.println("inputcount " + inputCount);
  822. // System.out.println("persentaseeee" + percentage);
  823. if(value > maxValue)
  824. {
  825. System.out.println("value lebih besar dari max curr");
  826. maxValue = value;
  827. maxKey = key;
  828. }
  829. }
  830. boolean xx = true;
  831. Iterator iterator2 = cache5.keySet().iterator();
  832. while (iterator2.hasNext()) {
  833. String key = iterator2.next().toString();
  834. int value = cache5.get(key);
  835. percentage = ((value*100)/sizeB);
  836. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  837. System.out.println("persentaseeee" + percentage);
  838. // System.out.println("currKey:"+key +"=== currVal: "+value);
  839. int threshold = tdbo.getThreshold();
  840. if( percentage < threshold)
  841. {
  842. System.out.println("masuk");
  843. System.out.println("xxxx" + xx);
  844. if (xx)
  845. {
  846. System.out.println("update point for " + key);
  847. tdbo.updateSitePoint(key);
  848. }
  849. tdbo.InsertHistory(key);
  850. xx = false;
  851. // System.out.println("max valueeee = "+ maxValue);
  852. // System.out.println("value sama besar dengan max value, add kedalam list");
  853. survivedKey.add(key);
  854. }
  855. }
  856. for (int i = 0; i < survivedKey.size(); i++) {
  857. System.out.println("TOP HITS !!! "+survivedKey.get(i));
  858. }
  859. result = maxKey;
  860. System.out.println("maxk "+maxKey+" maxv "+maxValue);
  861. if(survivedKey.size() == 0){
  862. topSites = null;
  863. }else{
  864. topSites = tdbo.TopSites(survivedKey, idWilayah, budgets);
  865. int times = 0;
  866. String wil = "";
  867. for(TourSite top : topSites){
  868. times = tdbo.GetTotalRecomTimes(top.getNama());
  869. // top.setWilayah(maxKey);
  870. top.setTimes(times);
  871. switch(top.getWilayah()){
  872. case "1": top.setWilayah("Bolaang Mongondouw"); break;
  873. case "2": top.setWilayah("Minahasa"); break;
  874. case "3": top.setWilayah("Sangihe"); break;
  875. case "4": top.setWilayah("Sitaro"); break;
  876. case "5": top.setWilayah("Talaud"); break;
  877. case "6": top.setWilayah("Manado"); break;
  878. case "7": top.setWilayah("Bitung"); break;
  879. case "8": top.setWilayah("Tomohon"); break;
  880. }
  881. }
  882. tdbo.insertTopRecomendations(topSites.get(0));
  883. }
  884. //insert to comment history
  885. return topSites;
  886. }
  887. public ArrayList<TourSite> getSitesAndRel(ArrayList<String> keywords, int idWilayah, int budgets){
  888. TourDBO tdbo = new TourDBO();
  889. ArrayList<String> sitesNames = new ArrayList<>();
  890. ArrayList<String> topSitesNames = new ArrayList<>();
  891. ArrayList<TourSite> topSites = new ArrayList();
  892. int inputCount = keywords.size();
  893. int match = 0;
  894. int percentage = 0;
  895. HashMap<String, Integer> sortedMap = new HashMap<String, Integer>();
  896. String result = "";
  897. sitesNames = tdbo.GetSiteNameWOR(keywords, idWilayah, budgets);
  898. System.out.println("sitname" + sitesNames);
  899. for(String siteName : sitesNames)
  900. {
  901. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  902. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  903. int occurence = 0;
  904. for(String word : itemsKey){
  905. // occurence = 0;
  906. for(String wordCompare : keywords){
  907. if(word.equalsIgnoreCase(wordCompare)){
  908. occurence ++;
  909. }
  910. }
  911. }
  912. cache4.put(siteName, occurence);
  913. }
  914. // tdbo.insertKeywordHistory(keyword);
  915. if(cache4.isEmpty()){
  916. // sitesNames = tdbo.GetSitesName(keyword, 0, 0);
  917. for(String keyword : keywords){
  918. sitesNames = tdbo.GetSiteNameWAnd(keywords, 0, 0);
  919. for(String siteName : sitesNames)
  920. {
  921. TourSite toursite2 = tdbo.GetSiteDetails(siteName);
  922. List<String> itemsKey = Arrays.asList(toursite2.getKeyword().split("\\s*,\\s*"));
  923. int occurence = 0;
  924. for(String word : itemsKey){
  925. // occurence = 0;
  926. for(String wordCompare : keywords){
  927. if(word.equalsIgnoreCase(wordCompare)){
  928. occurence ++;
  929. }
  930. }
  931. }
  932. cache4.put(siteName, occurence);
  933. }
  934. }
  935. }
  936. Iterator iterator = cache4.keySet().iterator();
  937. String maxKey = "";
  938. int maxValue = 0;
  939. ArrayList<String> survivedKey = new ArrayList<>();
  940. while (iterator.hasNext()) {
  941. String key = iterator.next().toString();
  942. int value = cache4.get(key);
  943. // percentage = ((value*100)/inputCount);
  944. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  945. System.out.println("valll" + value);
  946. // System.out.println("inputcount " + inputCount);
  947. // System.out.println("persentaseeee" + percentage);
  948. if(value > maxValue)
  949. {
  950. System.out.println("value lebih besar dari max curr");
  951. maxValue = value;
  952. maxKey = key;
  953. }
  954. }
  955. boolean xx = true;
  956. Iterator iterator2 = cache4.keySet().iterator();
  957. while (iterator2.hasNext()) {
  958. String key = iterator2.next().toString();
  959. int value = cache4.get(key);
  960. percentage = ((value*100)/inputCount);
  961. System.out.println("1111currKey:"+key +"=== currVal: "+value);
  962. System.out.println("persentaseeee" + percentage);
  963. // System.out.println("currKey:"+key +"=== currVal: "+value);
  964. int threshold = tdbo.getThreshold();
  965. if( percentage < threshold )
  966. {
  967. System.out.println("masuk");
  968. System.out.println("xxxx" + xx);
  969. if (xx)
  970. {
  971. System.out.println("update point for " + key);
  972. tdbo.updateSitePoint(key);
  973. }
  974. tdbo.InsertHistory(key);
  975. xx = false;
  976. // System.out.println("max valueeee = "+ maxValue);
  977. // System.out.println("value sama besar dengan max value, add kedalam list");
  978. survivedKey.add(key);
  979. }
  980. }
  981. for (int i = 0; i < survivedKey.size(); i++) {
  982. System.out.println("TOP HITS !!! "+survivedKey.get(i));
  983. }
  984. result = maxKey;
  985. System.out.println("maxk "+maxKey+" maxv "+maxValue);
  986. ArrayList<TourSite> newRes = new ArrayList<>();
  987. if(survivedKey.size() == 0){
  988. topSites = null;
  989. }else{
  990. System.out.println("masuk");
  991. topSites = tdbo.TopSites(survivedKey, idWilayah, budgets);
  992. // newRes = topSites;
  993. // Iterator it = topSites.iterator();
  994. // while(it.hasNext()){
  995. // for(TourSite ts : survived){
  996. // topSites.removeIf(p -> p.getNama().equalsIgnoreCase(ts.getNama()));
  997. // }
  998. // }
  999. // for(Iterator<TourSite> tops = topSites.iterator() ; tops.hasNext();){
  1000. // for(TourSite ts : survived){
  1001. //// if(tops.getNama().equalsIgnoreCase(ts.getNama())){
  1002. ////
  1003. //// }
  1004. // newRes.removeIf(p -> p.getNama().equalsIgnoreCase(ts.getNama()));
  1005. // }
  1006. // }
  1007. int times = 0;
  1008. String wil = "";
  1009. for(TourSite top : topSites){
  1010. times = tdbo.GetTotalRecomTimes(top.getNama());
  1011. // top.setWilayah(maxKey);
  1012. top.setTimes(times);
  1013. switch(top.getWilayah()){
  1014. case "1": top.setWilayah("Bolaang Mongondouw"); break;
  1015. case "2": top.setWilayah("Minahasa"); break;
  1016. case "3": top.setWilayah("Sangihe"); break;
  1017. case "4": top.setWilayah("Sitaro"); break;
  1018. case "5": top.setWilayah("Talaud"); break;
  1019. case "6": top.setWilayah("Manado"); break;
  1020. case "7": top.setWilayah("Bitung"); break;
  1021. case "8": top.setWilayah("Tomohon"); break;
  1022. }
  1023. }
  1024. System.out.println("tops" + topSites);
  1025. // for(TourSite tops : topSites ){
  1026. // for(TourSite ts : survived){
  1027. //// if(tops.getNama().equalsIgnoreCase(ts.getNama())){
  1028. ////
  1029. //// }
  1030. // newRes.removeIf(p -> p.getNama().equalsIgnoreCase(ts.getNama()));
  1031. // }
  1032. // }
  1033. // tdbo.insertTopRecomendations(topSites.get(0));
  1034. }
  1035. //insert to comment history
  1036. return topSites;
  1037. }
  1038. public static void main(String[] args) {
  1039. ArrayList<String> keywords1 = new ArrayList<>();
  1040. // keywords.add("wisata bahari");
  1041. // keywords.add("diving");
  1042. // keywords.add("wisata alam");
  1043. // keywords.add("danau");
  1044. // keywords.add("restaurant");
  1045. // keywords.add("wisata belanja");
  1046. // keywords.add("pasar");
  1047. // keywords.add("halal");
  1048. // keywords.add("wisata kuliner");
  1049. // keywords.add("restaurant");
  1050. keywords1.add("wisata bahari");
  1051. ArrayList<String> keywords = new ArrayList<>();
  1052. // keywords.add("wisata bahari");
  1053. // keywords.add("diving");
  1054. // keywords.add("wisata alam");
  1055. // keywords.add("danau");
  1056. // keywords.add("restaurant");
  1057. // keywords.add("wisata belanja");
  1058. // keywords.add("pasar");
  1059. // keywords.add("halal");
  1060. // keywords.add("wisata kuliner");
  1061. // keywords.add("restaurant");
  1062. keywords.add("wisata bahari");
  1063. keywords.add("diving");
  1064. keywords.add("swimming");
  1065. // keywords.add("jet ski");
  1066. // keywords.add("wisata alam");
  1067. // keywords.add("danau");
  1068. TourHelper th = new TourHelper();
  1069. System.out.println("sszz" + keywords.size());
  1070. ArrayList<TourSite> hasil = th.getSitesAnd2(keywords, 0, 0,6);
  1071. ArrayList<TourSite> hasilRelated = th.getSitesAndRel(keywords, 0, 0);
  1072. if(hasilRelated != null){
  1073. for(TourSite h : hasilRelated)
  1074. {
  1075. System.out.println("HASILLLL:" + h.getNama());
  1076. }
  1077. }else{
  1078. System.out.println("tidak ada yang cocok");
  1079. }
  1080. System.out.println("IS OTHER WILAYAH" + th.isOtherWilayah);
  1081. // System.out.println("OLD KEY==="+keywords);
  1082. // keywords.removeIf(p -> p.contains("wisata belanja"));
  1083. // System.out.println("NEW KEY==="+keywords);
  1084. }
  1085. }