Skip to content

Commit

Permalink
working version
Browse files Browse the repository at this point in the history
  • Loading branch information
Liyuse committed Apr 29, 2018
2 parents a53685e + a6c9221 commit 96514ba
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/app/cafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ export class Cafe {
name: string;
number: string;
address: string;
color: string;
distance: string;
status: string;
shape: string;
hours: string;
busyness: {number: [number,number]};
populartimes: object;
currentPop: number;
currVistNum: number;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/details/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
<button ion-button (click)="updateStatus({'status': 'red'})" color="danger" block>Full</button> -->
<ion-item>
<ion-label>How full is {{item["name"]}}?</ion-label>
<ion-range min="0" max="100" step="5" color="secondary" [(ngModel)]= item.percent></ion-range>
<ion-range #x (ionChange)="changeGradient(x.ratio, item.busyness[0][0])" min="0" max="100" step="5" color="{{item.color}}" [(ngModel)]= item.busyness[0][1]></ion-range>
</ion-item>
</p>

<ion-list detail-none>
<!-- cafe website link -->
<a href = "{{item['website']}}" ion-item>
<a href = "{{item['website']}}" target="_blank" ion-item>
<ion-icon name='ios-globe-outline' item-start></ion-icon>
Website
</a>
Expand Down
30 changes: 30 additions & 0 deletions src/pages/details/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export class DetailsPage {
var date = new Date();
var hours = date.getHours();
var day = date.getDay();
if(day===0){ // the day is sunday
day = 7
}
this.applemaps="http://maps.apple.com/?q="+this.item.address;

if (this.item.populartimes!=null) {
Expand All @@ -60,6 +63,18 @@ export class DetailsPage {
this.item.currentPop = 0;
}
this.cafe = adb.object('/cafe_list/' + this.item.place_id);

//kind of inefficient, but i couldnt call the function changeGradient here for some reason
if (this.item.busyness[0][1]/100 <= 0.3){
this.item.color = "secondary";
}
else if(this.item.busyness[0][1]/100 <= 0.6){
this.item.color = "orange"
}
else {
this.item.color = "danger";
}
console.log(this.item);
}
navigate(){
if (this.platform.is('mobileweb') || this.platform.is('core')) {
Expand All @@ -84,6 +99,21 @@ export class DetailsPage {
this.cafe.update(color);
}

changeGradient(ratio: any, timestamp: any){
if (ratio <= 0.3){
this.item.color = "secondary";
}
else if(ratio <= 0.6){
this.item.color = "orange"
}
else {
this.item.color = "danger";
}
//var busyness = {'busyness': {'0': [timestamp, ratio*100] }}
//this.cafes.update(busyness)
}


updateDataOfDay():void {
if(this.item.populartimes!=null){
// if the data exists in firebase, get them from firebase and parse popular times info
Expand Down
15 changes: 12 additions & 3 deletions src/pages/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,25 @@ export class HomePage
data=>
{
this.apiResults = data["results"];

console.log(this.apiResults);

this.matchedResults = this.apiResults;
var i = 0;
var showNum = 0;
var resLen = Object.keys(this.apiResults).length;

while(i < resLen && showNum < maxShowLen){
var apiResult = this.apiResults[i]
var id = apiResult.place_id;
let res = this.adb.object('/cafe_list/'+id);
res.valueChanges().subscribe(item => {
// if cafe's id doesn't exist in firebase, add it to firebase with its distance info
if(item["id"]!=undefined){

console.log("find one");
console.log(item);
if(item!=null && item['id']!=undefined){

//console.log(apiResult["geometry"]);
item["distance"] = compute_distance(userCoords, item["coordinates"]);
var newStatus = chooseColor(getCurrentPop(item));
this.adb.object('/cafe_list/'+item["id"]).update({ status: newStatus});
Expand Down Expand Up @@ -104,7 +110,10 @@ function getCurrentPop(cafe){
return -1;
// if the data doesn't exist, return -1 make the color become black
}else{
return cafe.populartimes[day-1]["data"][hours];
if(day===0){ // the day is sunday
day = 7
}
return cafe.populartimes[(day-1)]["data"][hours];
// get the data from firebase
}
}
Expand Down

0 comments on commit 96514ba

Please sign in to comment.