Browse Source

TC: Added data engineering code for ads

Toby Chui 5 years ago
parent
commit
bd6cc200ae

BIN
Thumbs.db


BIN
src/ads/Thumbs.db


BIN
src/ads/car.png


BIN
src/ads/clothes.png


BIN
src/ads/food.png


BIN
src/ads/travel.png


+ 11 - 1
src/index.php

@@ -19,6 +19,7 @@ $time = date("Y-m-d H:m:s");
 
 
 include_once("getUserImage.php"); //Handle user image location. Call with getUserIconpath()
 include_once("getUserImage.php"); //Handle user image location. Call with getUserIconpath()
 $userIcon = getUserIconPath();
 $userIcon = getUserIconPath();
+
 ?>
 ?>
 <html>
 <html>
 <head>
 <head>
@@ -106,7 +107,16 @@ $userIcon = getUserIconPath();
 				</div>
 				</div>
 			</div>
 			</div>
 		</div>
 		</div>
-		<!-- 聊天室列表--> 
+		<!-- Advertisment -->
+		<div class="ts segment" style='height:300px; overflow-y:auto;'>
+			<?php 
+				include_once("loadads.php");
+				$adspath = initAds();
+				echo '<img class="ts fluid image" src="'. $adspath .'"/>';
+			?>
+			
+		</div>
+		<!-- Chatroom List--> 
 		<div class="ts segment" style='height:300px; overflow-y:auto;'>
 		<div class="ts segment" style='height:300px; overflow-y:auto;'>
 <!--
 <!--
 			<div class="ts nopadding comments">
 			<div class="ts nopadding comments">

+ 48 - 0
src/loadads.php

@@ -0,0 +1,48 @@
+<?php
+//This is a function that returns the ads for this particular user by analysising his post keywords
+$keywords = '{
+	"car":["cars","car","drive","car dealer","car park","motorcycle","driving"],
+	"food":["restaurants","food","food court","sushi","rice","noodles","dim sum","cookies","icecream"],
+	"travel":["plane","travel","holiday","rest","tired","air ticket","trip","camping"],
+	"clothes":["clothes","dress","shorts","T-shirt","skirt"]
+}';
+$adsLinks = '{
+  "car":"ads/car.png",
+  "clothes":"ads/clothes.png",
+  "food":"ads/food.png",
+  "travel":"travel.png"
+}';
+$keywords = json_decode($keywords,true);
+$adsLinks = json_decode($adsLinks,true);
+include_once("requestDB.php"); //Get the sql loader from requestDB
+
+function initAds(){
+	global $keywords,$adsLinks;
+	$relatedPost = [];
+	$keys = [];
+	foreach ($keywords as $key => $value){
+		$thiskey = $key;
+		$thisKeywordList = $value;
+		$thisProb = 0;
+		foreach($thisKeywordList as $keyword){
+			$count = keywordCount($keyword);
+			$count = (int)$count[0]["pnum"];
+			$thisProb += $count;
+		}
+		array_push($keys,$thiskey);
+		array_push($relatedPost,$thisProb);
+	}
+	
+	//Get the highest prob which the user love this catergory.
+	$maxs = array_keys($relatedPost, max($relatedPost));
+	//The type of ads that we are going to show is:
+	//echo $keys[$maxs[0]];
+	return $adsLinks[$keys[$maxs[0]]];
+}
+
+function keywordCount($keyword){
+	$username = $_SESSION['login'];
+	$postData = query("select COUNT(*) as pnum from post WHERE username='" . $username ."' AND content LIKE '%$keyword%'","teabag");
+	return($postData);
+}
+?>

+ 1 - 0
src/userdata/cookieseeds/1573034408.auth

@@ -0,0 +1 @@
+04e25607d852783e655144070f1bc58635bd1c43ce139420c17d4b8d2d3831b42a93e943e6018669e14a4788ed51a8f62ef9ae188d8199f0b1c161c2d8dc42da

+ 1 - 0
src/userdata/cookieseeds/1573966490.auth

@@ -0,0 +1 @@
+fcc4f34f7638fe7ec956e5bd1906b0cbf15e9ac96a2dc80a913616b322fbea3c94e4dd11207457122a6f7c30299f7c5a7586e8e03f7d599c321108b956ba8370

+ 1 - 0
src/userdata/cookieseeds/1573969147.auth

@@ -0,0 +1 @@
+ea9f80cf5747a43c83ce9ddffc8c1819c0e8502b1050e75de474eeef8f9dbd7ef1934a165b92819e095edbedb5c914d0204b43ffa8bffe6346c741264aaa968d

+ 1 - 0
src/userdata/cookieseeds/1573970300.auth

@@ -0,0 +1 @@
+3bed4a126926f3588f65b9fad7393ff3186288eb2e31fa85f2383b1b9b1ea0458febbbc50259e745f9b68fdfc59c4bf778e293dde756f48c64406cf05c0d3962