Реализовать эвристическую / оценочную функцию в приложении Android - PullRequest
0 голосов
/ 19 февраля 2019

Я пытался разработать приложение, использующее для планирования встречи с автомобилем.Теперь у меня есть данные, которые отображаются в моем приложении в Android Studio, и я хочу сделать что-то умное, например, когда я нажимаю кнопку, она может выполнить оценку и изменить назначение листинга.

import org.json.JSONException;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private TextView mTextMessage;

    String[] dataDetail;
    ArrayList<dataDetail> allDetail = new ArrayList<>();

    ListView detailList;
    final Context context = this;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_home:
                    mTextMessage.setText(R.string.title_home);
                    return true;
                case R.id.navigation_dashboard:
                    mTextMessage.setText(R.string.title_dashboard);
                    return true;
                case R.id.navigation_notifications:
                    mTextMessage.setText(R.string.title_notifications);
                    return true;
            }
            return false;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        detailList = findViewById(R.id.dataView);

        mTextMessage = (TextView) findViewById(R.id.message);
        BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

        new GetData().execute();

    }

    private class GetData extends AsyncTask<Void, Void, ArrayList<dataDetail>> {

        protected ArrayList<dataDetail> doInBackground(Void... voids) {

            HttpURLConnection urlConnection;
            InputStream in = null;
            try {
                URL url = new URL("http://10.0.2.2:8080/projectServer/DataDetailDB?getdata=true");
                urlConnection = (HttpURLConnection) url.openConnection();
                in = new BufferedInputStream(urlConnection.getInputStream());
            } catch (IOException e) {
                e.printStackTrace();
            }
            String response = convertStreamToString(in);
            System.out.println("Server response = " + response);

            try {
                JSONArray jsonArray = new JSONArray(response);
                dataDetail = new String[jsonArray.length()];

                for (int i = 0; i < jsonArray.length(); i++) {

                    String customername = jsonArray.getJSONObject(i).get("customerName").toString();
                    String carname = jsonArray.getJSONObject(i).get("carName").toString();
                    String appointmentdate = jsonArray.getJSONObject(i).get("appointmentDate").toString();
                    String email = jsonArray.getJSONObject(i).get("email").toString();
                    String issuedescribe = jsonArray.getJSONObject(i).get("issueDescribe").toString();

                    dataDetail tData = new dataDetail(customername, carname, appointmentdate, email, issuedescribe);
                    allDetail.add(tData);

                    System.out.println("customername = " + customername + "carname = " + carname + "appointmentdate = " + appointmentdate +
                        "email = " + email + "describe = " + issuedescribe);
                    dataDetail [i] = "Name: " + customername + "\n" + "Appointment Date: " + appointmentdate;

                }

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        protected void onPostExecute(ArrayList<dataDetail> dataDetailArrayList) {
            super.onPostExecute(dataDetailArrayList);

            ArrayAdapter theList = new ArrayAdapter(context, android.R.layout.simple_list_item_1, dataDetail);
            detailList.setAdapter(theList);
        }
    }

    public String convertStreamToString(InputStream is) {
        java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
        return s.hasNext() ? s.next() : "";
    }
}

Я думал использовать эвристику для оценки, например:

W1 * Время работы + W2 * Надежно на автомобиле + W3 *расстояние между заданием + W4 * стоимость.

В зависимости от того, какой результат получено на каждой встрече, затем измените порядок следования списка, причем важный или более высокий балл будет наверху списка.

Теперь я просто понятия не имею, как я могу запустить или реализовать его в Java.Кто-нибудь может дать мне какой-нибудь совет или комментарий, это будет очень полезно.

Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...