Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.fyp.activityrecommendation;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Toast;
- import org.apache.http.NameValuePair;
- import org.apache.http.message.BasicNameValuePair;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- /**
- * Created by ThemuRR on 22/03/15.
- */
- public class Algorithm
- {
- int time;
- int age;
- int gender;
- int act;
- int adv;
- int cul;
- int spo;
- int hgt;
- int fail = 0;
- int beau = 0;
- String weather;
- String wind;
- double wspeed;
- String rain = "Rain";
- String sun = "Sun";
- String clear = "Clear";
- String drizzle = "Drizzle";
- String extreme = "Extreme";
- String snow = "Snow";
- String thunderstorm = "Thunderstorm";
- String clouds = "Clouds";
- String opennow = "";
- String type = "";
- String keyword = "";
- String name = "||";
- String result1 = "";
- String gend = "";
- String response;
- public Algorithm()
- {
- this.time = HomeScreen.getTime();
- this.age = HomeScreen.getAge();
- this.gender = HomeScreen.getGender();
- this.act = HomeScreen.getAct();
- this.adv = HomeScreen.getAdven();
- this.cul = HomeScreen.getCul();
- this.spo = HomeScreen.getSport();
- this.hgt = HomeScreen.getHeight();
- this.beau = 0;
- this.weather = HomeScreen.getWeather();
- this.wind = HomeScreen.getWspeed();
- this.wspeed = Double.parseDouble(wind);
- this.algo();
- }
- public void algo()
- {
- String beau1;
- String age1;
- String act1;
- String cul1;
- String adv1;
- String spo1;
- String hgt1;
- String gender1;
- beau1 = String.valueOf(beau);
- age1 = String.valueOf(age);
- act1 = String.valueOf(act);
- cul1 = String.valueOf(cul);
- adv1 = String.valueOf(adv);
- spo1 = String.valueOf(spo);
- hgt1 = String.valueOf(hgt);
- gender1 = String.valueOf(gender);
- String[] keys;
- if (wspeed < 0.3) {
- beau = 0;
- } else if (wspeed >0.3 && wspeed < 1.5) {
- beau = 1;
- } else if (wspeed >1.5 && wspeed < 3.3) {
- beau = 2;
- } else if (wspeed > 3.3 && wspeed < 5.5) {
- beau = 3;
- } else if (wspeed > 5.5 && wspeed < 8) {
- beau = 4;
- } else if (wspeed > 8 && wspeed < 10.8) {
- beau = 5;
- } else if (wspeed > 10.8 && wspeed < 13.9) {
- beau = 6;
- } else if (wspeed > 13.9 && wspeed < 17.2) {
- beau = 7;
- } else if (wspeed > 17.2 && wspeed < 20.7) {
- beau = 8;
- } else if (wspeed > 20.7 && wspeed < 24.5) {
- beau = 9;
- } else if (wspeed > 24.5) {
- beau = 10;
- }
- ArrayList<NameValuePair> postParameters = new ArrayList<>();
- // define the parameters
- postParameters.add(new BasicNameValuePair("weather", weather));
- postParameters.add(new BasicNameValuePair("wind", beau1));
- postParameters.add(new BasicNameValuePair("gender", gender1));
- postParameters.add(new BasicNameValuePair("age", age1));
- postParameters.add(new BasicNameValuePair("act", act1));
- postParameters.add(new BasicNameValuePair("cul", cul1));
- postParameters.add(new BasicNameValuePair("adv", adv1));
- postParameters.add(new BasicNameValuePair("spo", spo1));
- postParameters.add(new BasicNameValuePair("hgt", hgt1));
- try
- {
- response = CustomHttpClient.executeHttpPost(
- "http://itsthemurr.com/getact.php", postParameters);
- String result = response.toString();
- try
- {
- JSONArray jArray = new JSONArray(result);
- for (int i = 0; i < jArray.length(); i++)
- {
- JSONObject json_data = jArray.getJSONObject(i);
- keys = new String[i];
- if(json_data.has("kword"))
- keyword += json_data.getString("kword");
- keys[i] = keyword;
- }
- } catch (JSONException e) {
- Log.e("log_tag", "Error parsing data " + e.toString());
- }
- } catch (Exception e) {
- Log.e("log_tag", "Error in http connection!!" + e.toString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement