Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.57 KB | None | 0 0
  1. package com.fyp.activityrecommendation;
  2.  
  3. import android.os.Bundle;
  4. import android.util.Log;
  5. import android.view.View;
  6. import android.widget.Toast;
  7.  
  8. import org.apache.http.NameValuePair;
  9. import org.apache.http.message.BasicNameValuePair;
  10. import org.json.JSONArray;
  11. import org.json.JSONException;
  12. import org.json.JSONObject;
  13.  
  14. import java.util.ArrayList;
  15.  
  16. /**
  17.  * Created by ThemuRR on 22/03/15.
  18.  */
  19. public class Algorithm
  20. {
  21.     int time;
  22.  
  23.     int age;
  24.     int gender;
  25.     int act;
  26.     int adv;
  27.     int cul;
  28.     int spo;
  29.     int hgt;
  30.     int fail = 0;
  31.     int beau = 0;
  32.  
  33.     String weather;
  34.     String wind;
  35.     double wspeed;
  36.  
  37.     String rain = "Rain";
  38.     String sun = "Sun";
  39.     String clear = "Clear";
  40.     String drizzle = "Drizzle";
  41.     String extreme = "Extreme";
  42.     String snow = "Snow";
  43.     String thunderstorm = "Thunderstorm";
  44.     String clouds = "Clouds";
  45.  
  46.     String opennow = "";
  47.     String type = "";
  48.     String keyword = "";
  49.     String name = "||";
  50.     String result1 = "";
  51.  
  52.     String gend = "";
  53.  
  54.     String response;
  55.     public Algorithm()
  56.     {
  57.         this.time = HomeScreen.getTime();
  58.         this.age = HomeScreen.getAge();
  59.         this.gender = HomeScreen.getGender();
  60.         this.act = HomeScreen.getAct();
  61.         this.adv = HomeScreen.getAdven();
  62.         this.cul = HomeScreen.getCul();
  63.         this.spo = HomeScreen.getSport();
  64.         this.hgt = HomeScreen.getHeight();
  65.         this.beau = 0;
  66.         this.weather = HomeScreen.getWeather();
  67.         this.wind = HomeScreen.getWspeed();
  68.         this.wspeed = Double.parseDouble(wind);
  69.         this.algo();
  70.  
  71.  
  72.  
  73.  
  74.     }
  75.  
  76.     public void algo()
  77.     {
  78.         String beau1;
  79.         String age1;
  80.         String act1;
  81.         String cul1;
  82.         String adv1;
  83.         String spo1;
  84.         String hgt1;
  85.         String gender1;
  86.         beau1 = String.valueOf(beau);
  87.         age1 = String.valueOf(age);
  88.         act1 = String.valueOf(act);
  89.         cul1 = String.valueOf(cul);
  90.         adv1 = String.valueOf(adv);
  91.         spo1 = String.valueOf(spo);
  92.         hgt1 = String.valueOf(hgt);
  93.         gender1 = String.valueOf(gender);
  94.         String[] keys;
  95.  
  96.         if (wspeed < 0.3) {
  97.             beau = 0;
  98.         } else if (wspeed >0.3 && wspeed < 1.5) {
  99.             beau = 1;
  100.         } else if (wspeed >1.5 && wspeed < 3.3) {
  101.             beau = 2;
  102.         } else if (wspeed > 3.3 && wspeed < 5.5) {
  103.             beau = 3;
  104.         } else if (wspeed > 5.5 && wspeed < 8) {
  105.             beau = 4;
  106.         } else if (wspeed > 8 && wspeed < 10.8) {
  107.             beau = 5;
  108.         } else if (wspeed > 10.8 && wspeed < 13.9) {
  109.             beau = 6;
  110.         } else if (wspeed > 13.9 && wspeed < 17.2) {
  111.             beau = 7;
  112.         } else if (wspeed > 17.2 && wspeed < 20.7) {
  113.             beau = 8;
  114.         } else if (wspeed > 20.7 && wspeed < 24.5) {
  115.             beau = 9;
  116.         } else if (wspeed > 24.5) {
  117.             beau = 10;
  118.         }
  119.  
  120.  
  121.         ArrayList<NameValuePair> postParameters = new ArrayList<>();
  122.  
  123.  
  124.         // define the parameters
  125.         postParameters.add(new BasicNameValuePair("weather", weather));
  126.         postParameters.add(new BasicNameValuePair("wind", beau1));
  127.         postParameters.add(new BasicNameValuePair("gender", gender1));
  128.         postParameters.add(new BasicNameValuePair("age", age1));
  129.         postParameters.add(new BasicNameValuePair("act", act1));
  130.         postParameters.add(new BasicNameValuePair("cul", cul1));
  131.         postParameters.add(new BasicNameValuePair("adv", adv1));
  132.         postParameters.add(new BasicNameValuePair("spo", spo1));
  133.         postParameters.add(new BasicNameValuePair("hgt", hgt1));
  134.  
  135.  
  136.  
  137.         try
  138.         {
  139.             response = CustomHttpClient.executeHttpPost(
  140.                     "http://itsthemurr.com/getact.php", postParameters);
  141.  
  142.             String result = response.toString();
  143.  
  144.             try
  145.             {
  146.                 JSONArray jArray = new JSONArray(result);
  147.  
  148.                 for (int i = 0; i < jArray.length(); i++)
  149.                 {
  150.                     JSONObject json_data = jArray.getJSONObject(i);
  151.                     keys = new String[i];
  152.  
  153.                     if(json_data.has("kword"))
  154.                         keyword += json_data.getString("kword");
  155.                         keys[i] = keyword;
  156.                 }
  157.  
  158.  
  159.             } catch (JSONException e) {
  160.                 Log.e("log_tag", "Error parsing data " + e.toString());
  161.  
  162.             }
  163.  
  164.         } catch (Exception e) {
  165.             Log.e("log_tag", "Error in http connection!!" + e.toString());
  166.         }
  167.  
  168.  
  169.  
  170.     }
  171.  
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement