Browse Source

added photo, fixes cor error

old
Yiğit Çolakoğlu 6 years ago
parent
commit
db8c2174bf
45 changed files with 23025 additions and 11575 deletions
  1. +4
    -1
      MyCity/app/build.gradle
  2. +12
    -4
      MyCity/app/src/main/AndroidManifest.xml
  3. +53
    -13
      MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java
  4. +5
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java
  5. +3
    -2
      MyCity/app/src/main/java/gq/yigit/mycity/QRFragment.java
  6. +67
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/TakePhoto.java
  7. +25
    -26
      MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java
  8. +58
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityElectricity.java
  9. +58
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityWater.java
  10. +29
    -0
      MyCity/app/src/main/res/layout/activity_take_photo.xml
  11. +1
    -1
      MyCity/app/src/main/res/layout/fragment_utility.xml
  12. +6
    -6
      MyCity/app/src/main/res/layout/fragment_utility_electricity.xml
  13. +6
    -6
      MyCity/app/src/main/res/layout/fragment_utility_water.xml
  14. +1
    -0
      MyCity/build.gradle
  15. +3
    -1
      client_side/interface/UserData/denunciation_map.html
  16. +8
    -6
      client_side/interface/UserData/qr_info.html
  17. +4
    -2
      client_side/interface/UserData/ratings.html
  18. +5
    -2
      client_side/interface/UserData/voting_results.html
  19. +9
    -3
      client_side/modules/qr/user_data.py
  20. +56
    -0
      server_side/api/modules/SpotSelector.py
  21. BIN
      server_side/api/modules/__pycache__/denunciation.cpython-37.pyc
  22. BIN
      server_side/api/modules/__pycache__/navigation.cpython-37.pyc
  23. BIN
      server_side/api/modules/__pycache__/rating_system.cpython-37.pyc
  24. BIN
      server_side/api/modules/__pycache__/utility.cpython-37.pyc
  25. BIN
      server_side/api/modules/__pycache__/voting_system.cpython-37.pyc
  26. +1
    -0
      server_side/api/modules/createData.py
  27. +22505
    -11455
      server_side/api/modules/databases/bus.json
  28. +1
    -0
      server_side/api/modules/databases/locations.json
  29. +3
    -0
      server_side/api/modules/databases/park_data.json
  30. +26
    -2
      server_side/api/modules/databases/users.json
  31. +18
    -2
      server_side/api/modules/denunciation.py
  32. +24
    -30
      server_side/api/modules/detectSpots.py
  33. +9
    -3
      server_side/api/modules/navigation.py
  34. BIN
      server_side/api/modules/parking_images/1.jpg
  35. BIN
      server_side/api/modules/parking_images/2.jpg
  36. BIN
      server_side/api/modules/parking_images/3.jpg
  37. BIN
      server_side/api/modules/parking_images/4.jpg
  38. BIN
      server_side/api/modules/parking_images/5.jpg
  39. BIN
      server_side/api/modules/parking_images/6.jpg
  40. BIN
      server_side/api/modules/parking_images/7.jpg
  41. BIN
      server_side/api/modules/parking_images/8.jpg
  42. BIN
      server_side/api/modules/parking_images/main.jpg
  43. +12
    -4
      server_side/api/modules/rating_system.py
  44. +3
    -3
      server_side/api/modules/utility.py
  45. +10
    -3
      server_side/api/modules/voting_system.py

+ 4
- 1
MyCity/app/build.gradle View File

@ -10,6 +10,7 @@ android {
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
android.defaultConfig.vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
release {
@ -20,9 +21,11 @@ android {
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
api 'cz.msebera.android:httpclient:4.4.1.2'
implementation 'com.google.zxing:core:3.2.0'
implementation 'com.github.chathuralakmal:AndroidImagePopup:1.2.1'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
implementation 'com.jjoe64:graphview:4.2.2'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:27.0.0'


+ 12
- 4
MyCity/app/src/main/AndroidManifest.xml View File

@ -1,8 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gq.yigit.mycity">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission-sdk-23 android:name="android.permission.CAMERA" />
<uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
@ -10,11 +16,13 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".TakePhoto">
</activity>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>


+ 53
- 13
MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java View File

@ -2,6 +2,7 @@ package gq.yigit.mycity;
import android.Manifest;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@ -28,6 +29,7 @@ import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@ -49,7 +51,9 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons
private EditText note;
private Bitmap img;
private ImageButton img_button;
private static final int CAMERA_REQUEST = 1888;
private static final int CAMERA_REQUEST = 100;
private Uri mImageUri;
public DenunciationFragment() {
}
@ -72,23 +76,25 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons
View rootView = inflater.inflate(R.layout.fragment_denunciation, container, false);
FileActions file_manager = new FileActions();
url = file_manager.readFromFile(getContext(),"server.config").trim();
activity=this;
submit = rootView.findViewById(R.id.denunciation_submit);
note = (EditText) rootView.findViewById(R.id.denunciation_text);
img_button= rootView.findViewById(R.id.denunciation_photo);
spinner = rootView.findViewById(R.id.denunciation_spinner);
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
img_button.setEnabled(false);
ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
}
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -117,14 +123,27 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons
request.execute();
}
});
img_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
File photo;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try
{
// place where to store camera taken picture
photo = createTemporaryFile("picture", ".jpg");
photo.delete();
Uri mImageUri = Uri.fromFile(photo);
}
catch(Exception e)
{
Log.v("[ERROR]", "Can't create file to take picture!");
Toast.makeText(getContext(), "Please check SD card! Image shot is impossible!", Toast.LENGTH_LONG);
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
//start camera intent
activity.startActivityForResult(intent, CAMERA_REQUEST);
}
});
@ -158,6 +177,17 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons
}
}
private File createTemporaryFile(String part, String ext) throws Exception
{
File tempDir= Environment.getExternalStorageDirectory();
tempDir=new File(tempDir.getAbsolutePath()+"/.temp/");
if(!tempDir.exists())
{
tempDir.mkdirs();
}
return File.createTempFile(part, ext, tempDir);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
@ -232,6 +262,20 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons
}
//called after camera intent finished
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
//MenuShootImage is user defined menu option to shoot image
if(requestCode==CAMERA_REQUEST && resultCode==RESULT_OK)
{
Bitmap photo = (Bitmap) data.getExtras().get("data");
img = photo;
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 0) {
@ -242,8 +286,4 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons
}
}
}

+ 5
- 0
MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java View File

@ -4,10 +4,12 @@ import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
@ -102,6 +104,7 @@ public class MainActivity extends AppCompatActivity
transaction.replace(R.id.app_bar_main, fragment);
transaction.addToBackStack(null);
transaction.commit();
Log.d("[BOOKMARK]","Done with main");
}
@ -247,4 +250,6 @@ public class MainActivity extends AppCompatActivity
Log.e("[ERROR]","Cannot set avatar!");
}
}
}

+ 3
- 2
MyCity/app/src/main/java/gq/yigit/mycity/QRFragment.java View File

@ -12,8 +12,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.google.zxing.WriterException;
import com.google.zxing.WriterException;
import org.json.JSONException;
import gq.yigit.mycity.tools.QRCodeGenerator;
@ -46,8 +46,9 @@ public class QRFragment extends Fragment {
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_qr, container, false);
qr_view = rootView.findViewById(R.id.qr_image);
try {
qr_img = QRCodeGenerator.Generate(MainActivity.userData.getString("id"),429,429);
qr_img = QRCodeGenerator.Generate(MainActivity.userData.getString("id"),1080,1080);
qr_view.setImageBitmap(qr_img);
}catch(JSONException e){
Log.e("[ERROR]","JSON error occured while generating qr code!");


+ 67
- 0
MyCity/app/src/main/java/gq/yigit/mycity/TakePhoto.java View File

@ -0,0 +1,67 @@
package gq.yigit.mycity;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class TakePhoto extends AppCompatActivity {
private Button takePictureButton;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_take_photo);
takePictureButton = (Button) findViewById(R.id.button_image);
imageView = (ImageView) findViewById(R.id.imageview);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
takePictureButton.setEnabled(false);
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 0) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) {
takePictureButton.setEnabled(true);
}
}
}
public void takePicture(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 100);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 100) {
Log.d("[BOOKMARK]","Actvitity resulted");
if (resultCode == RESULT_OK) {
if (data == null) {
Log.d("[BOOKMARK]","Received image");
// TODO Do something with the full image stored
// in outputFileUri. Perhaps copying it to the app folder
}
}
}
}
}

+ 25
- 26
MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java View File

@ -3,7 +3,6 @@ package gq.yigit.mycity.tools;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.Uri;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
@ -16,30 +15,30 @@ import static android.graphics.Color.BLACK;
import static android.graphics.Color.WHITE;
public class QRCodeGenerator {
public static Bitmap Generate(String data, int height,int width) throws WriterException {
BitMatrix result;
try {
result = new MultiFormatWriter().encode(data,
BarcodeFormat.QR_CODE, width, height, null);
} catch (IllegalArgumentException iae) {
// Unsupported format
return null;
}
int w = result.getWidth();
int h = result.getHeight();
int[] pixels = new int[w * h];
for (int y = 0; y < h; y++) {
int offset = y * w;
for (int x = 0; x < w; x++) {
pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
}
}
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, w, 0, 0, w, h);
return bitmap;
}
public static Bitmap Generate(String data, int height,int width) throws WriterException {
BitMatrix result;
try {
result = new MultiFormatWriter().encode(data,
BarcodeFormat.QR_CODE, width, height, null);
} catch (IllegalArgumentException iae) {
// Unsupported format
return null;
}
int w = result.getWidth();
int h = result.getHeight();
int[] pixels = new int[w * h];
for (int y = 0; y < h; y++) {
int offset = y * w;
for (int x = 0; x < w; x++) {
pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
}
}
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, w, 0, 0, w, h);
return bitmap;
}
}

+ 58
- 0
MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityElectricity.java View File

@ -1,7 +1,9 @@
package gq.yigit.mycity.utility;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
@ -10,6 +12,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.ceylonlabs.imageviewpopup.ImagePopup;
import com.google.zxing.WriterException;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.helper.StaticLabelsFormatter;
import com.jjoe64.graphview.series.DataPoint;
@ -17,6 +24,7 @@ import com.jjoe64.graphview.series.LineGraphSeries;
import gq.yigit.mycity.MainActivity;
import gq.yigit.mycity.R;
import gq.yigit.mycity.tools.FileActions;
import gq.yigit.mycity.tools.QRCodeGenerator;
import gq.yigit.mycity.tools.WebRequest;
import org.json.JSONException;
import org.json.JSONObject;
@ -29,6 +37,14 @@ public class UtilityElectricity extends Fragment implements WebRequest.responseL
private JSONObject electricityUsage;
private GraphView graph;
private TextView bill;
private TextView points;
private TextView efficiency;
private Button qr_view;
private Button pay_bill;
private OnFragmentInteractionListener mListener;
public UtilityElectricity() {
@ -54,6 +70,44 @@ public class UtilityElectricity extends Fragment implements WebRequest.responseL
View rootView = inflater.inflate(R.layout.fragment_utility_electricity, container, false);;
graph = (GraphView) rootView.findViewById(R.id.utility_graph);
points = rootView.findViewById(R.id.points_utility_electricity);
bill = rootView.findViewById(R.id.bill_utility_electricity);
efficiency = rootView.findViewById(R.id.efficiency_utility_electricity);
pay_bill = rootView.findViewById(R.id.pay_bill_electricity);
qr_view = rootView.findViewById(R.id.use_point_electricity);
pay_bill.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getContext(),"Bills paid successfully!",Toast.LENGTH_LONG).show();
}
});
final ImagePopup imagePopup = new ImagePopup(getContext());
imagePopup.setWindowHeight(712); // Optional
imagePopup.setWindowWidth(712); // Optional
imagePopup.setBackgroundColor(Color.WHITE); // Optional
imagePopup.setFullScreen(true); // Optional
imagePopup.setImageOnClickClose(true); // Optional
try {
imagePopup.initiatePopup(new BitmapDrawable(QRCodeGenerator.Generate(MainActivity.userData.getString("id"), 712, 712)));
}catch (JSONException e){
Log.e("[ERROR]","Cannot get user id");
}catch (WriterException e){
Log.e("[ERROR]","Writer exception occured");
}
qr_view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
imagePopup.viewPopup();
}
});
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"0", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24"});
@ -130,6 +184,10 @@ public class UtilityElectricity extends Fragment implements WebRequest.responseL
graph.addSeries(series);
graph.addSeries(series2);
points.setText(String.valueOf(((Double)electricityUsage.get("points")).intValue()));
bill.setText(String.valueOf(((Double)electricityUsage.get("bill")).intValue()));
efficiency.setText(String.valueOf(((Double)electricityUsage.get("efficiency")).intValue()));
}catch (JSONException e){
Log.e("[ERROR]","Cannot interpret response from electric service");
}


+ 58
- 0
MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityWater.java View File

@ -1,7 +1,9 @@
package gq.yigit.mycity.utility;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
@ -10,6 +12,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.ceylonlabs.imageviewpopup.ImagePopup;
import com.google.zxing.WriterException;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.helper.StaticLabelsFormatter;
import com.jjoe64.graphview.series.DataPoint;
@ -17,6 +24,7 @@ import com.jjoe64.graphview.series.LineGraphSeries;
import gq.yigit.mycity.MainActivity;
import gq.yigit.mycity.R;
import gq.yigit.mycity.tools.FileActions;
import gq.yigit.mycity.tools.QRCodeGenerator;
import gq.yigit.mycity.tools.WebRequest;
import org.json.JSONException;
import org.json.JSONObject;
@ -29,6 +37,14 @@ public class UtilityWater extends Fragment implements WebRequest.responseListene
private JSONObject waterUsage;
private GraphView graph;
private TextView bill;
private TextView points;
private TextView efficiency;
private Button qr_view;
private Button pay_bill;
private OnFragmentInteractionListener mListener;
public UtilityWater() {
@ -54,6 +70,43 @@ public class UtilityWater extends Fragment implements WebRequest.responseListene
View rootView = inflater.inflate(R.layout.fragment_utility_water, container, false);;
graph = (GraphView) rootView.findViewById(R.id.utility_graph);
points = rootView.findViewById(R.id.points_utility_water);
bill = rootView.findViewById(R.id.bill_utility_water);
efficiency = rootView.findViewById(R.id.efficiency_utility_water);
pay_bill = rootView.findViewById(R.id.pay_bill_water);
qr_view = rootView.findViewById(R.id.use_point_water);
pay_bill.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getContext(),"Bills paid successfully!",Toast.LENGTH_LONG).show();
}
});
final ImagePopup imagePopup = new ImagePopup(getContext());
imagePopup.setWindowHeight(712); // Optional
imagePopup.setWindowWidth(712); // Optional
imagePopup.setBackgroundColor(Color.WHITE); // Optional
imagePopup.setFullScreen(true); // Optional
imagePopup.setImageOnClickClose(true); // Optional
try {
imagePopup.initiatePopup(new BitmapDrawable(QRCodeGenerator.Generate(MainActivity.userData.getString("id"), 712, 712)));
}catch (JSONException e){
Log.e("[ERROR]","Cannot get user id");
}catch (WriterException e){
Log.e("[ERROR]","Writer exception occured");
}
qr_view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
imagePopup.viewPopup();
}
});
StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
staticLabelsFormatter.setHorizontalLabels(new String[] {"0", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24"});
@ -123,6 +176,7 @@ public class UtilityWater extends Fragment implements WebRequest.responseListene
true,
100);
}
series.setTitle("ideal");
series.setColor(Color.BLUE);
series2.setTitle("usage");
@ -130,6 +184,10 @@ public class UtilityWater extends Fragment implements WebRequest.responseListene
graph.addSeries(series);
graph.addSeries(series2);
points.setText(String.valueOf(((Double)waterUsage.get("points")).intValue()));
bill.setText(String.valueOf(((Double)waterUsage.get("bill")).intValue()));
efficiency.setText(String.valueOf(((Double)waterUsage.get("efficiency")).intValue()));
}catch (JSONException e){
Log.e("[ERROR]","Cannot interpret response from water service");
}


+ 29
- 0
MyCity/app/src/main/res/layout/activity_take_photo.xml View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TakePhoto">
<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/button_image"/>
<Button
android:id="@+id/button_image"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="takePicture"
android:text="Take a picture!"/>
</RelativeLayout>

+ 1
- 1
MyCity/app/src/main/res/layout/fragment_utility.xml View File

@ -6,7 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".utility.UtilityMain" android:orientation="vertical"
android:layout_marginTop="@dimen/fragment_margin">
android:layout_marginTop="55dp">


+ 6
- 6
MyCity/app/src/main/res/layout/fragment_utility_electricity.xml View File

@ -31,7 +31,7 @@ android:orientation="vertical">
<TextView
android:text="Content Here"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/bill_utility"
android:layout_height="wrap_content" android:id="@+id/bill_utility_electricity"
android:textColor="@android:color/black" android:textSize="16sp"
android:layout_marginVertical="4dp" android:layout_marginHorizontal="7dp"
android:layout_weight="1"/>
@ -50,7 +50,7 @@ android:orientation="vertical">
<TextView
android:text="Content Here"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/points_utility"
android:layout_height="wrap_content" android:id="@+id/points_utility_electricity"
android:textColor="@android:color/black" android:textSize="16sp"
android:layout_marginVertical="4dp" android:layout_marginHorizontal="7dp"
android:layout_weight="1"/>
@ -69,7 +69,7 @@ android:orientation="vertical">
<TextView
android:text="Content Here"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/efficiency_utility"
android:layout_height="wrap_content" android:id="@+id/efficiency_utility_electricity"
android:textColor="@android:color/black" android:textSize="16sp"
android:layout_marginVertical="4dp" android:layout_marginHorizontal="7dp"
android:layout_weight="1"/>
@ -82,11 +82,11 @@ android:orientation="vertical">
<Button
android:text="Pay Bill"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/pay_bill" android:layout_weight="1"/>
android:layout_height="wrap_content" android:id="@+id/pay_bill_electricity" android:layout_weight="1"/>
<Button
android:text="use points"
android:text="Use Points"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/use_point" android:layout_weight="1"/>
android:layout_height="wrap_content" android:id="@+id/use_point_electricity" android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

+ 6
- 6
MyCity/app/src/main/res/layout/fragment_utility_water.xml View File

@ -31,7 +31,7 @@
<TextView
android:text="Content Here"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/bill_utility"
android:layout_height="wrap_content" android:id="@+id/bill_utility_water"
android:textColor="@android:color/black" android:textSize="16sp"
android:layout_marginVertical="4dp" android:layout_marginHorizontal="7dp"
android:layout_weight="1"/>
@ -50,7 +50,7 @@
<TextView
android:text="Content Here"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/points_utility"
android:layout_height="wrap_content" android:id="@+id/points_utility_water"
android:textColor="@android:color/black" android:textSize="16sp"
android:layout_marginVertical="4dp" android:layout_marginHorizontal="7dp"
android:layout_weight="1"/>
@ -69,7 +69,7 @@
<TextView
android:text="Content Here"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/efficiency_utility"
android:layout_height="wrap_content" android:id="@+id/efficiency_utility_water"
android:textColor="@android:color/black" android:textSize="16sp"
android:layout_marginVertical="4dp" android:layout_marginHorizontal="7dp"
android:layout_weight="1"/>
@ -82,11 +82,11 @@
<Button
android:text="Pay Bill"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/pay_bill" android:layout_weight="1"/>
android:layout_height="wrap_content" android:id="@+id/pay_bill_water" android:layout_weight="1"/>
<Button
android:text="use points"
android:text="Use Points"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/use_point" android:layout_weight="1"/>
android:layout_height="wrap_content" android:id="@+id/use_point_water" android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

+ 1
- 0
MyCity/build.gradle View File

@ -17,6 +17,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {


+ 3
- 1
client_side/interface/UserData/denunciation_map.html View File

@ -37,7 +37,9 @@
for (var i = 0; i < markers.length; i++) {
markers.pop().setMap(null);
}
$.get("https://127.0.0.1:5000/denunciations", function(data, status){
$.get("https://127.0.0.1:5000/denunciations", function(dataStr, status){
data = $.parseJSON(dataStr)
if (status == "success") {
data.forEach(function(element) {
var marker = new google.maps.Marker({


+ 8
- 6
client_side/interface/UserData/qr_info.html View File

@ -33,13 +33,15 @@
<script>
setInterval(function() {
$.get("http://127.0.0.1:3000/get", function(data, status){
userData = $.parseJSON(data)
if (status == "success") {
document.getElementById("userpic").src = "https://0.0.0.0:5000" + data["avatar"];
document.getElementById("name").innerHTML = data["realname"];
document.getElementById("tc").innerHTML = data["TC"];
document.getElementById("health").innerHTML = data["health"].join(", ");
document.getElementById("number").innerHTML = data["tel"];
document.getElementById("email").innerHTML = data["email"];
console.log(data)
document.getElementById("userpic").src = "https://0.0.0.0:5000" + userData["avatar"];
document.getElementById("name").innerHTML = userData["realname"];
document.getElementById("tc").innerHTML = userData["TC"];
document.getElementById("health").innerHTML = userData["health"].join(", ");
document.getElementById("number").innerHTML = userData["tel"];
document.getElementById("email").innerHTML = userData["email"];
}
});
}, 2000);


+ 4
- 2
client_side/interface/UserData/ratings.html View File

@ -7,7 +7,8 @@
</head>
<body>
<script>
$.get("https://127.0.0.1:5000/ratings", function(data, status){
$.get("https://127.0.0.1:5000/ratings", function(dataStr, status){
data = $.parseJSON(dataStr)
if (status == "success") {
data.forEach(function(element) {
var a = document.createElement('a');
@ -22,7 +23,8 @@
});
function results(id) {
$.get("https://127.0.0.1:5000/ratings/" + id, function(data, status){
$.get("https://127.0.0.1:5000/ratings/" + id, function(dataStr, status){
data = $.parseJSON(dataStr)
if (status == "success") {
var results = document.getElementById("results")
results.innerHTML = '';


+ 5
- 2
client_side/interface/UserData/voting_results.html View File

@ -40,7 +40,9 @@
return color;
}
$.get("https://127.0.0.1:5000/votings", function(data, status){
$.get("https://127.0.0.1:5000/votings", function(dataStr, status){
data = $.parseJSON(dataStr)
if (status == "success") {
data.forEach(function(element) {
var a = document.createElement('a');
@ -55,7 +57,8 @@
});
function graph(id) {
$.get("https://127.0.0.1:5000/votings/" + id, function(data, status){
$.get("https://127.0.0.1:5000/votings/" + id, function(dataStr, status){
data = $.parseJSON(dataStr)
if (status == "success") {
config["data"]["datasets"][0]["label"] = data["name"]
config["data"]["datasets"][0]["data"] = []


+ 9
- 3
client_side/modules/qr/user_data.py View File

@ -1,4 +1,4 @@
from flask import Flask, jsonify, request, abort
from flask import Flask, jsonify, request, abort,Response
from multiprocessing import Process
import requests
@ -28,13 +28,19 @@ qr_reader = Reader()
def set_data():
global user
user = json.loads(request.form['data'])
return ''
resp = Response("OK")
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
@app.route('/get')
def get_qr():
if user == {}:
abort(404)
return jsonify(user)
resp = Response(json.dumps(user))
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
app.run(host='0.0.0.0', port=3000)

+ 56
- 0
server_side/api/modules/SpotSelector.py View File

@ -0,0 +1,56 @@
import cv2
import json
rects = []
im = cv2.imread("parking_images/main.jpg")
if __name__ == '__main__' :
while(True):
scale_percent = 50
width = int(im.shape[1] * scale_percent / 100)
height = int(im.shape[0] * scale_percent / 100)
# Select ROI
fromCenter = False
r = cv2.selectROI(cv2.resize(im,(width,height)))
# Crop image
if(r == (0,0,0,0)):
cv2.destroyAllWindows()
break
imCrop = im[int(r[1]*100/scale_percent):int(r[1]*100/scale_percent+r[3]*100/scale_percent), int(r[0]*100/scale_percent):int(r[0]*100/scale_percent+r[2]*100/scale_percent)]
# Display cropped image
cv2.imshow("Image", imCrop)
cv2.waitKey(0)
cv2.destroyAllWindows()
rects.append([])
print(rects[len(rects)-1])
for i in r:
rects[len(rects)-1].append(int(i)*int(100/scale_percent))
print(rects)
locs = {}
for i in range(len(rects)):
loc = rects[i]
locs[str(i)] = {
"x1": loc[0],
"y1": loc[1],
"x2": loc[0]+loc[2],
"y2": loc[1]+loc[3],
"priority":i
}
with open("databases/locations.json","w") as f:
f.write(json.dumps(locs,indent=4))

BIN
server_side/api/modules/__pycache__/denunciation.cpython-37.pyc View File


BIN
server_side/api/modules/__pycache__/navigation.cpython-37.pyc View File


BIN
server_side/api/modules/__pycache__/rating_system.cpython-37.pyc View File


BIN
server_side/api/modules/__pycache__/utility.cpython-37.pyc View File


BIN
server_side/api/modules/__pycache__/voting_system.cpython-37.pyc View File


+ 1
- 0
server_side/api/modules/createData.py View File

@ -0,0 +1 @@
def getVals(img,loc):

+ 22505
- 11455
server_side/api/modules/databases/bus.json
File diff suppressed because it is too large
View File


+ 1
- 0
server_side/api/modules/databases/locations.json View File

@ -0,0 +1 @@
{}

+ 3
- 0
server_side/api/modules/databases/park_data.json View File

@ -0,0 +1,3 @@
{
}

+ 26
- 2
server_side/api/modules/databases/users.json View File

@ -92,8 +92,32 @@
12
],
"ideal_water_usage": [
1
11,
11,
11,
11,
11,
12,
14,
15,
15,
15,
15,
15,
15,
15,
15,
15,
15,
16,
16,
15,
15,
14,
12
],
"points": 50
"points": 50,
"electricity_bill": 100,
"water_bill": 120
}
}

+ 18
- 2
server_side/api/modules/denunciation.py View File

@ -1,10 +1,15 @@
from api.modules import utils
from flask import Flask, request
from flask import Flask, request,Response
from flask_restful import Resource, Api, abort
import json
import os
import base64
from PIL import Image
import cv2
from io import BytesIO
import numpy as np
app = Flask(__name__)
api = Api(app)
@ -17,11 +22,19 @@ users_path = os.path.join(app.root_path, 'databases', 'users.json')
with open(users_path, 'r') as f:
users = json.load(f)
def readb64(base64_string):
sbuf = BytesIO()
sbuf.write(base64.b64decode(base64_string))
pimg = Image.open(sbuf)
return cv2.cvtColor(np.array(pimg), cv2.COLOR_RGB2BGR)
class Alert(Resource):
def post(self):
args = request.form
cvimg = readb64(args["photo"])
username= ""
for user in users:
if users[user]["id"] == args["id"]:
@ -36,7 +49,7 @@ class Alert(Resource):
class Denunciations(Resource):
def get(self):
return [
resp = Response(json.dumps([
{
'id' : v['id'],
'info': v['info'],
@ -45,7 +58,10 @@ class Denunciations(Resource):
}
for v in denunciations
]
))
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
class Denounce(Resource):
def post(self):


server_side/api/modules/alternateSolution1.py → server_side/api/modules/detectSpots.py View File


+ 9
- 3
server_side/api/modules/navigation.py View File

@ -63,7 +63,7 @@ def time_diff(t1, t2):
if time2.minute - time1.minute >= 0:
response += str(abs(time2.hour - time1.hour))
else:
response += str(abs(time2.hour - time1.hour) - 1)
response += str(abs(abs(time2.hour - time1.hour)-1))
response += ":"
@ -178,7 +178,7 @@ class Transit(Resource):
"http://88.255.141.66/mbl/android/action.asp?SID=0.8737969480190279&VER=3.1.0&LAN=tr"
"&UID"
"=%7BACB78701-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=HatBilgileri",
"KOD={}".format(routes_arr["user"][j.strip()]))["data"][0]["table_durak"]
"KOD={}".format(j.strip()))["data"][0]["table_durak"]
bus_json["stops"][j.strip()] = [x["kod"] for x in stops]
routes_arr["user"][j.strip()] = bus_json["stops"][j.strip()]
for x in stops:
@ -200,7 +200,7 @@ class Transit(Resource):
"http://88.255.141.66/mbl/android/action.asp?SID=0.8737969480190279&VER=3.1.0&LAN=tr"
"&UID"
"=%7BACB78701-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=HatBilgileri",
"KOD={}".format(routes_arr["dest"][j.strip()]))["data"][0]["table_durak"]
"KOD={}".format(j.strip()))["data"][0]["table_durak"]
bus_json["stops"][j.strip()] = [x["kod"] for x in stops]
routes_arr["dest"][j.strip()] = bus_json["stops"][j.strip()]
for x in stops:
@ -307,11 +307,17 @@ class Transit(Resource):
travel["routes"].pop(i)
if change:
bus_data = open("modules/databases/bus.json", "w")
bus_data.write(json.dumps(bus_json, indent=4, sort_keys=True))
bus_data.close()
for route in travel["routes"]:
start = route[0]["time"][0]
end = route[-1]["time"][1]
diff = time_diff(start, end)
print (route)
print (diff)
diff = time_sum(diff, time_diff(time_cur.strftime("%H:%M"), start))
diff = time_sum(diff, "00:05")
travel["total"].append(diff)


BIN
server_side/api/modules/parking_images/1.jpg View File

Before After
Width: 1440  |  Height: 1080  |  Size: 248 KiB

BIN
server_side/api/modules/parking_images/2.jpg View File

Before After
Width: 1440  |  Height: 1080  |  Size: 242 KiB

BIN
server_side/api/modules/parking_images/3.jpg View File

Before After
Width: 1440  |  Height: 1080  |  Size: 225 KiB

BIN
server_side/api/modules/parking_images/4.jpg View File

Before After
Width: 1440  |  Height: 1080  |  Size: 225 KiB

BIN
server_side/api/modules/parking_images/5.jpg View File

Before After
Width: 1440  |  Height: 1080  |  Size: 253 KiB

BIN
server_side/api/modules/parking_images/6.jpg View File

Before After
Width: 1440  |  Height: 1080  |  Size: 236 KiB

BIN
server_side/api/modules/parking_images/7.jpg View File

Before After
Width: 1440  |  Height: 1080  |  Size: 302 KiB

BIN
server_side/api/modules/parking_images/8.jpg View File

Before After
Width: 1440  |  Height: 1080  |  Size: 276 KiB

BIN
server_side/api/modules/parking_images/main.jpg View File

Before After
Width: 1440  |  Height: 1080  |  Size: 248 KiB

+ 12
- 4
server_side/api/modules/rating_system.py View File

@ -4,7 +4,7 @@ import json
from api.modules import utils
from flask import Flask, request
from flask import Flask, request, Response
from flask_restful import Resource, Api, abort
app = Flask(__name__)
@ -21,7 +21,8 @@ with open(user_db, 'r') as f:
class Ratings(Resource):
def get(self):
return [
resp = Response(json.dumps([
{
'id' : v['id'],
'name': v['name'],
@ -29,7 +30,10 @@ class Ratings(Resource):
'img' : v['img']
}
for v in ratings
]
]))
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
def post(self):
"""
@ -85,7 +89,11 @@ class Ratings(Resource):
class Rating(Resource):
def get(self, rating_id):
try:
return ratings[rating_id - 1]
resp = Response(json.dumps(ratings[rating_id - 1]))
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
except:
abort(404, error="Rating {} doesn't exist".format(rating_id))


+ 3
- 3
server_side/api/modules/utility.py View File

@ -18,7 +18,7 @@ class Resources(Resource):
def post(self):
"""
POST Data:
user_id=<id>&type=<electricity|water>&bill=<bill>
user_id=<id>&type=<electricity|water>
:return:
"""
user = utils.find_by_id(users.values(), request.form['user_id'])
@ -32,7 +32,7 @@ class Resources(Resource):
point = 10 - (sum_diff * 0.0001)
eff = point * 10
bill = (int(request.form['bill']) * eff)/100
bill = ( user['electricity_bill'] * eff)/100
return {
'daily_electricity_usage': usage,
'ideal_electricity_usage': ideal,
@ -51,7 +51,7 @@ class Resources(Resource):
point = 10 - (sum_diff * 0.0001)
eff = point * 10
bill = (int(request.form['bill']) * eff)/100
bill = (user['water_bill'] * eff)/100
return {
'daily_water_usage': usage,


+ 10
- 3
server_side/api/modules/voting_system.py View File

@ -4,7 +4,7 @@ import json
from api.modules import utils
from flask import Flask, request
from flask import Flask, request,Response
from flask_restful import Resource, Api, abort
app = Flask(__name__)
@ -20,6 +20,7 @@ with open(user_db, 'r') as f:
class Votings(Resource):
def get(self):
voting = [
{
'id' : v['id'],
@ -29,7 +30,11 @@ class Votings(Resource):
}
for v in votings
]
return voting
resp = Response(json.dumps(voting))
resp.headers['Access-Control-Allow-Origin'] = '*'
return resp
def post(self):
"""
@ -78,8 +83,10 @@ class Voting(Resource):
try:
voting = copy.deepcopy(votings[voting_id - 1])
del voting['voters']
resp = Response(json.dumps(voting))
resp.headers['Access-Control-Allow-Origin'] = '*'
return voting
return resp
except:
abort(404, error="Voting {} doesn't exist".format(voting_id))


Loading…
Cancel
Save