@ -0,0 +1,306 @@ | |||
package gq.yigit.mycity.navigation; | |||
import android.content.Context; | |||
import android.content.Intent; | |||
import android.location.Location; | |||
import android.location.LocationManager; | |||
import android.net.Uri; | |||
import android.os.Bundle; | |||
import android.support.v4.app.Fragment; | |||
import android.support.v7.widget.LinearLayoutManager; | |||
import android.support.v7.widget.RecyclerView; | |||
import android.util.Log; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.ImageView; | |||
import android.widget.LinearLayout; | |||
import android.widget.TextView; | |||
import com.google.android.gms.common.api.Status; | |||
import com.google.android.gms.maps.model.LatLng; | |||
import com.google.android.libraries.places.api.Places; | |||
import com.google.android.libraries.places.api.model.Place; | |||
import com.google.android.libraries.places.api.model.RectangularBounds; | |||
import com.google.android.libraries.places.api.net.PlacesClient; | |||
import com.google.android.libraries.places.widget.Autocomplete; | |||
import com.google.android.libraries.places.widget.AutocompleteActivity; | |||
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode; | |||
import gq.yigit.mycity.R; | |||
import gq.yigit.mycity.tools.FileActions; | |||
import gq.yigit.mycity.tools.WebRequest; | |||
import org.json.JSONArray; | |||
import org.json.JSONException; | |||
import org.json.JSONObject; | |||
import java.util.*; | |||
import static android.app.Activity.RESULT_CANCELED; | |||
import static android.app.Activity.RESULT_OK; | |||
import static gq.yigit.mycity.MainActivity.apikey; | |||
import static gq.yigit.mycity.MainActivity.cntxt; | |||
public class TransitFragment extends Fragment implements WebRequest.responseListener { | |||
private OnFragmentInteractionListener mListener; | |||
private OnRecyclerViewInteractionListener recyclerViewInteractionListener; | |||
private TextView place_name; | |||
private String[] place_data = {"","","",""}; | |||
private PlacesClient placesClient; | |||
private String url; | |||
private String longitude; | |||
private String latitude; | |||
private RecyclerView recyclerView; | |||
public TransitFragment() { | |||
// Required empty public constructor | |||
} | |||
public static TransitFragment newInstance(String param1, String param2) { | |||
TransitFragment fragment = new TransitFragment(); | |||
return fragment; | |||
} | |||
@Override | |||
public void onCreate(Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
} | |||
@Override | |||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |||
Bundle savedInstanceState) { | |||
View rootView = inflater.inflate(R.layout.fragment_transit, container, false); | |||
LinearLayout search_button = rootView.findViewById(R.id.search_layout); | |||
search_button.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View view) { | |||
Places.initialize(getContext(), apikey); | |||
placesClient = Places.createClient(getContext()); | |||
int AUTOCOMPLETE_REQUEST_CODE = 1; | |||
List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME,Place.Field.LAT_LNG); | |||
Intent intent = new Autocomplete.IntentBuilder( | |||
AutocompleteActivityMode.FULLSCREEN, fields). | |||
setLocationRestriction(RectangularBounds.newInstance(new LatLng(39.7281252,32.4848006),new LatLng(40.061707,32.9889204))) | |||
.build(getContext()); | |||
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE); | |||
} | |||
}); | |||
place_name = rootView.findViewById(R.id.place_name); | |||
recyclerView = rootView.findViewById(R.id.route_view); | |||
try { | |||
LocationManager locationManager = (LocationManager) | |||
getContext().getSystemService(cntxt.LOCATION_SERVICE); | |||
Location loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); | |||
longitude = String.valueOf((double)loc.getLongitude()); | |||
latitude = String.valueOf(loc.getLatitude()); | |||
}catch (SecurityException e){ | |||
Log.e("[ERROR]","An error occured with location permissions"); | |||
} | |||
return rootView; | |||
} | |||
public void onButtonPressed(Uri uri) { | |||
if (mListener != null) { | |||
mListener.onFragmentInteraction(uri); | |||
} | |||
} | |||
@Override | |||
public void onAttach(Context context) { | |||
super.onAttach(context); | |||
if (context instanceof OnFragmentInteractionListener) { | |||
mListener = (OnFragmentInteractionListener) context; | |||
} else { | |||
throw new RuntimeException(context.toString() | |||
+ " must implement OnFragmentInteractionListener"); | |||
} | |||
} | |||
@Override | |||
public void onDetach() { | |||
super.onDetach(); | |||
mListener = null; | |||
} | |||
public interface OnFragmentInteractionListener { | |||
// TODO: Update argument type and name | |||
void onFragmentInteraction(Uri uri); | |||
} | |||
@Override | |||
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |||
if (requestCode == 1) { | |||
if (resultCode == RESULT_OK) { | |||
Place place = Autocomplete.getPlaceFromIntent(data); | |||
place_data[0] = place.getName(); | |||
place_data[1] = place.getId(); | |||
Log.i("[INFO]", "Place: " + place.getName() + ", " + place.getId()); | |||
place_name.setText(place_data[0]); | |||
place_data[2] = String.valueOf(place.getLatLng().latitude); | |||
place_data[3] = String.valueOf(place.getLatLng().longitude); | |||
FileActions file_manager = new FileActions(); | |||
url = file_manager.readFromFile(cntxt,"server.config").trim(); | |||
HashMap<String,String> args = new HashMap<>(); | |||
args.put("lat_usr",latitude); | |||
args.put("lng_usr",longitude); | |||
args.put("lat_dest",place_data[2]); | |||
args.put("lng_dest",place_data[3]); | |||
WebRequest request = new WebRequest(url + "/transit",false, args,0); | |||
request.addListener(this); | |||
request.execute(); | |||
} else if (resultCode == AutocompleteActivity.RESULT_ERROR) { | |||
Status status = Autocomplete.getStatusFromIntent(data); | |||
Log.i("[INFO]", status.getStatusMessage()); | |||
} else if (resultCode == RESULT_CANCELED) { | |||
} | |||
} | |||
} | |||
@Override | |||
public void receivedResponse(boolean success,String response, int reqid){ | |||
Log.i("[INFO]",response); | |||
try{ | |||
JSONObject travel = new JSONObject(response); | |||
JSONArray routes = new JSONArray(travel.getString("routes")); | |||
for(int i = 0; i< routes.length();i++){ | |||
JSONObject route = new JSONObject(routes.getString(i)); | |||
TransitContent.addItem(new TransitContent.TransitItem( | |||
route.getString("name"), | |||
(new JSONArray(route.getString("stops")).getString(0)), | |||
(new JSONArray(route.getString("stops")).getString(1)), | |||
(new JSONArray(route.getString("time")).getString(0)), | |||
(new JSONArray(route.getString("time")).getString(1)), | |||
"bus" | |||
)); | |||
} | |||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); | |||
recyclerView.setAdapter(new TransitAdapter(TransitContent.ITEMS, recyclerViewInteractionListener)); | |||
}catch (JSONException e){ | |||
Log.e("[ERROR]", "Received invalid response from public transport service!"); | |||
} | |||
} | |||
public interface OnRecyclerViewInteractionListener { | |||
void OnRecyclerViewInteractionListener(TransitContent.TransitItem item); | |||
} | |||
} | |||
class TransitContent { | |||
public static final List<TransitItem> ITEMS = new ArrayList<TransitItem>(); | |||
public static final Map<String, TransitItem> ITEM_MAP = new HashMap<String, TransitItem>(); | |||
public static void addItem(TransitItem item) { | |||
ITEMS.add(item); | |||
ITEM_MAP.put(item.endTime, item); | |||
} | |||
public static class TransitItem { | |||
public final String lineNo; | |||
public final String startName; | |||
public final String endName; | |||
public final String startTime; | |||
public final String endTime; | |||
public final String type; | |||
public TransitItem(String lineNo, String startName, String endName, String startTime, String endTime, String type) { | |||
this.lineNo = lineNo; | |||
this.startName = startName; | |||
this.endName = endName; | |||
this.startTime = startTime; | |||
this.endTime = endTime; | |||
this.type = type; | |||
} | |||
} | |||
} | |||
class TransitAdapter extends RecyclerView.Adapter<TransitAdapter.ViewHolder>{ | |||
private final List<TransitContent.TransitItem> mValues; | |||
private final TransitFragment.OnRecyclerViewInteractionListener mListener; | |||
public TransitAdapter(List<TransitContent.TransitItem> items, TransitFragment.OnRecyclerViewInteractionListener listener) { | |||
mValues = items; | |||
mListener = listener; | |||
} | |||
@Override | |||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |||
View view = LayoutInflater.from(parent.getContext()) | |||
.inflate(R.layout.transit_item, parent, false); | |||
return new ViewHolder(view); | |||
} | |||
@Override | |||
public void onBindViewHolder(final ViewHolder holder, int position) { | |||
holder.mItem = mValues.get(position); | |||
holder.stop1.setText(mValues.get(position).startName); | |||
holder.stop2.setText(mValues.get(position).endName); | |||
holder.time1.setText(mValues.get(position).startTime); | |||
holder.time2.setText(mValues.get(position).endTime); | |||
holder.line.setText(mValues.get(position).lineNo); | |||
String type = mValues.get(position).type; | |||
if(type.equals("bus")){ | |||
}else if(type.equals("subway") || type.equals("ankaray")){ | |||
}else if(type.equals("walk")){} | |||
holder.mView.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (null != mListener) { | |||
mListener.OnRecyclerViewInteractionListener(holder.mItem); | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public int getItemCount() { | |||
return mValues.size(); | |||
} | |||
public class ViewHolder extends RecyclerView.ViewHolder { | |||
private final View mView; | |||
private final TextView stop1; | |||
private final TextView stop2; | |||
private final ImageView type; | |||
private final TextView line; | |||
private final TextView time1; | |||
private final TextView time2; | |||
private TransitContent.TransitItem mItem; | |||
private ViewHolder(View view) { | |||
super(view); | |||
mView = view; | |||
stop1 = view.findViewById(R.id.stop1_addr); | |||
stop2 = view.findViewById(R.id.stop2_addr); | |||
time1 = view.findViewById(R.id.stop1_time); | |||
time2 = view.findViewById(R.id.stop2_time); | |||
line = view.findViewById(R.id.line_no); | |||
type = view.findViewById(R.id.type_img); | |||
} | |||
} | |||
} |
@ -0,0 +1,12 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:innerRadius="0dp" | |||
android:shape="ring" | |||
android:thicknessRatio="1.9" | |||
android:useLevel="false" > | |||
<solid android:color="@android:color/transparent" /> | |||
<stroke | |||
android:width="10dp" | |||
android:color="@android:color/white" /> | |||
</shape> |
@ -0,0 +1,11 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:shape="rectangle"> | |||
<corners | |||
android:radius="6dp"/> | |||
<stroke | |||
android:width="0dp" | |||
android:color="#c9c9c9" /> | |||
<solid android:color="#0019B9" /> | |||
</shape> |
@ -0,0 +1,10 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:shape="rectangle"> | |||
<corners | |||
android:radius="20dp"/> | |||
<stroke | |||
android:width="2dp" | |||
android:color="#c9c9c9" /> | |||
<solid android:color="#e9e9e9" /> | |||
</shape> |
@ -0,0 +1,37 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
tools:context=".navigation.TransitFragment" | |||
android:layout_marginTop="@dimen/fragment_margin" | |||
android:orientation="vertical"> | |||
<LinearLayout | |||
android:orientation="horizontal" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" android:id="@+id/search_layout" | |||
android:background="@drawable/search_shape" | |||
android:layout_marginHorizontal="10dp" | |||
android:paddingHorizontal="5dp" | |||
android:layout_marginBottom="30dp"> | |||
<ImageView | |||
android:layout_width="70dp" | |||
android:layout_height="40dp" android:id="@+id/rate_item_img" | |||
android:layout_weight="1" | |||
android:layout_marginRight="5dp" app:srcCompat="@drawable/magnifier" | |||
android:layout_marginVertical="5dp" | |||
android:layout_marginLeft="10dp"/> | |||
<TextView | |||
android:text="Please select a place" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" android:id="@+id/place_name" android:layout_weight="1" | |||
android:gravity="center_vertical" android:textColor="#FF616161" android:textSize="16sp" | |||
android:layout_marginLeft="7dp"/> | |||
</LinearLayout> | |||
<android.support.v7.widget.RecyclerView | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" android:id="@+id/route_view" | |||
android:layout_marginLeft="8dp"/> | |||
</LinearLayout> |
@ -0,0 +1,72 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:orientation="horizontal"> | |||
<LinearLayout | |||
android:orientation="vertical" | |||
android:layout_width="wrap_content" | |||
android:layout_height="150dp" | |||
android:gravity="center" | |||
android:background="@drawable/line_shape" | |||
android:padding="2dp" | |||
android:layout_marginRight="7dp"> | |||
<ImageView | |||
android:layout_width="30dp" | |||
android:layout_height="30dp" app:srcCompat="@drawable/bus" android:id="@+id/type_img" | |||
android:background="@drawable/circle_shape" | |||
android:padding="2dp"/> | |||
</LinearLayout> | |||
<android.support.constraint.ConstraintLayout | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent" android:id="@+id/linearLayout"> | |||
<TextView | |||
android:text="TextView" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" android:id="@+id/stop1_addr" | |||
android:textColor="#000000" | |||
android:textSize="15sp" | |||
app:layout_constraintTop_toTopOf="parent" | |||
app:layout_constraintStart_toStartOf="parent" | |||
android:layout_marginStart="8dp" android:layout_marginTop="8dp"/> | |||
<TextView | |||
android:text="TextView" | |||
android:layout_width="64dp" | |||
android:layout_height="wrap_content" android:id="@+id/stop1_time" | |||
android:textColor="#000000" android:textSize="15sp" | |||
app:layout_constraintTop_toTopOf="@+id/stop1_addr" | |||
app:layout_constraintStart_toEndOf="@+id/stop1_addr" android:layout_marginStart="4dp"/> | |||
<TextView | |||
android:text="TextView" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" android:id="@+id/line_no" | |||
android:textColor="#000000" | |||
android:layout_marginTop="64dp" app:layout_constraintTop_toTopOf="parent" | |||
android:textSize="16sp" android:layout_marginStart="8dp" | |||
app:layout_constraintStart_toStartOf="@+id/stop2_addr"/> | |||
<TextView | |||
android:text="TextView" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" android:id="@+id/stop2_addr" | |||
android:textColor="#000000" android:textSize="15sp" | |||
android:layout_marginBottom="8dp" | |||
app:layout_constraintBottom_toBottomOf="parent" | |||
app:layout_constraintStart_toStartOf="@+id/stop1_addr"/> | |||
<TextView | |||
android:text="TextView" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" android:id="@+id/stop2_time" | |||
android:textColor="#000000" | |||
android:textSize="15sp" | |||
app:layout_constraintBottom_toBottomOf="@+id/stop2_addr" | |||
app:layout_constraintStart_toStartOf="@+id/stop1_time"/> | |||
</android.support.constraint.ConstraintLayout> | |||
</LinearLayout> |
@ -0,0 +1,9 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<module type="PYTHON_MODULE" version="4"> | |||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |||
<exclude-output /> | |||
<content url="file://$MODULE_DIR$" /> | |||
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" /> | |||
<orderEntry type="sourceFolder" forTests="false" /> | |||
</component> | |||
</module> |
@ -0,0 +1,31 @@ | |||
<!DOCTYPE html> | |||
<html lang="en"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>UserInterface</title> | |||
<link rel="stylesheet" href="style.css"> | |||
<script src="socket.io/dist/socket.io.js"></script> | |||
<script src = "index.js"></script> | |||
</head> | |||
<body> | |||
<div id = "basics"> | |||
<span class="inline"><img src="https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Ftse4.mm.bing.net%2Fth%3Fid%3DOIP.ELnJq_JhiyfewhCMKOkNfwHaHa%26pid%3DApi&f=1" id="userpic" alt=""></span> | |||
<span class="inline"> | |||
<table> | |||
<tr> | |||
<td class="table-header"><solid>Name:</solid></td> | |||
<td id = "name"></td> | |||
<td class="table-header"><solid>TC:</solid></td> | |||
<td id = "tc"></td> | |||
<td class="table-header"><solid>Status:</solid></td> | |||
<td id = "status"></td> | |||
</tr> | |||
<tr> | |||
<td class="table-header"><solid>Health info:</solid></td> | |||
<td id = "health"></td> | |||
</tr> | |||
</table> | |||
</span> | |||
</div> | |||
</body> | |||
</html> |
@ -0,0 +1,4 @@ | |||
var exampleSocket = new WebSocket("ws://localhost:3000", "protocolOne"); | |||
exampleSocket.onmessage = function (event) { | |||
console.log(event.data); | |||
} |
@ -0,0 +1,333 @@ | |||
{ | |||
"requires": true, | |||
"lockfileVersion": 1, | |||
"dependencies": { | |||
"accepts": { | |||
"version": "1.3.5", | |||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", | |||
"integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", | |||
"requires": { | |||
"mime-types": "2.1.23", | |||
"negotiator": "0.6.1" | |||
} | |||
}, | |||
"after": { | |||
"version": "0.8.2", | |||
"resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz", | |||
"integrity": "sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=" | |||
}, | |||
"arraybuffer.slice": { | |||
"version": "0.0.7", | |||
"resolved": "https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz", | |||
"integrity": "sha512-wGUIVQXuehL5TCqQun8OW81jGzAWycqzFF8lFp+GOM5BXLYj3bKNsYC4daB7n6XjCqxQA/qgTJ+8ANR3acjrog==" | |||
}, | |||
"async-limiter": { | |||
"version": "1.0.0", | |||
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", | |||
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" | |||
}, | |||
"backo2": { | |||
"version": "1.0.2", | |||
"resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", | |||
"integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc=" | |||
}, | |||
"base64-arraybuffer": { | |||
"version": "0.1.5", | |||
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz", | |||
"integrity": "sha1-c5JncZI7Whl0etZmqlzUv5xunOg=" | |||
}, | |||
"base64id": { | |||
"version": "1.0.0", | |||
"resolved": "https://registry.npmjs.org/base64id/-/base64id-1.0.0.tgz", | |||
"integrity": "sha1-R2iMuZu2gE8OBtPnY7HDLlfY5rY=" | |||
}, | |||
"better-assert": { | |||
"version": "1.0.2", | |||
"resolved": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz", | |||
"integrity": "sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI=", | |||
"requires": { | |||
"callsite": "1.0.0" | |||
} | |||
}, | |||
"blob": { | |||
"version": "0.0.5", | |||
"resolved": "https://registry.npmjs.org/blob/-/blob-0.0.5.tgz", | |||
"integrity": "sha512-gaqbzQPqOoamawKg0LGVd7SzLgXS+JH61oWprSLH+P+abTczqJbhTR8CmJ2u9/bUYNmHTGJx/UEmn6doAvvuig==" | |||
}, | |||
"callsite": { | |||
"version": "1.0.0", | |||
"resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz", | |||
"integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA=" | |||
}, | |||
"component-bind": { | |||
"version": "1.0.0", | |||
"resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz", | |||
"integrity": "sha1-AMYIq33Nk4l8AAllGx06jh5zu9E=" | |||
}, | |||
"component-emitter": { | |||
"version": "1.2.1", | |||
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz", | |||
"integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=" | |||
}, | |||
"component-inherit": { | |||
"version": "0.0.3", | |||
"resolved": "https://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz", | |||
"integrity": "sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM=" | |||
}, | |||
"cookie": { | |||
"version": "0.3.1", | |||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", | |||
"integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" | |||
}, | |||
"debug": { | |||
"version": "4.1.1", | |||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", | |||
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", | |||
"requires": { | |||
"ms": "2.1.1" | |||
} | |||
}, | |||
"engine.io": { | |||
"version": "3.3.2", | |||
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-3.3.2.tgz", | |||
"integrity": "sha512-AsaA9KG7cWPXWHp5FvHdDWY3AMWeZ8x+2pUVLcn71qE5AtAzgGbxuclOytygskw8XGmiQafTmnI9Bix3uihu2w==", | |||
"requires": { | |||
"accepts": "1.3.5", | |||
"base64id": "1.0.0", | |||
"cookie": "0.3.1", | |||
"debug": "3.1.0", | |||
"engine.io-parser": "2.1.3", | |||
"ws": "6.1.4" | |||
}, | |||
"dependencies": { | |||
"debug": { | |||
"version": "3.1.0", | |||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", | |||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", | |||
"requires": { | |||
"ms": "2.0.0" | |||
} | |||
}, | |||
"ms": { | |||
"version": "2.0.0", | |||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", | |||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" | |||
} | |||
} | |||
}, | |||
"engine.io-client": { | |||
"version": "3.3.2", | |||
"resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-3.3.2.tgz", | |||
"integrity": "sha512-y0CPINnhMvPuwtqXfsGuWE8BB66+B6wTtCofQDRecMQPYX3MYUZXFNKDhdrSe3EVjgOu4V3rxdeqN/Tr91IgbQ==", | |||
"requires": { | |||
"component-emitter": "1.2.1", | |||
"component-inherit": "0.0.3", | |||
"debug": "3.1.0", | |||
"engine.io-parser": "2.1.3", | |||
"has-cors": "1.1.0", | |||
"indexof": "0.0.1", | |||
"parseqs": "0.0.5", | |||
"parseuri": "0.0.5", | |||
"ws": "6.1.4", | |||
"xmlhttprequest-ssl": "1.5.5", | |||
"yeast": "0.1.2" | |||
}, | |||
"dependencies": { | |||
"debug": { | |||
"version": "3.1.0", | |||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", | |||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", | |||
"requires": { | |||
"ms": "2.0.0" | |||
} | |||
}, | |||
"ms": { | |||
"version": "2.0.0", | |||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", | |||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" | |||
} | |||
} | |||
}, | |||
"engine.io-parser": { | |||
"version": "2.1.3", | |||
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-2.1.3.tgz", | |||
"integrity": "sha512-6HXPre2O4Houl7c4g7Ic/XzPnHBvaEmN90vtRO9uLmwtRqQmTOw0QMevL1TOfL2Cpu1VzsaTmMotQgMdkzGkVA==", | |||
"requires": { | |||
"after": "0.8.2", | |||
"arraybuffer.slice": "0.0.7", | |||
"base64-arraybuffer": "0.1.5", | |||
"blob": "0.0.5", | |||
"has-binary2": "1.0.3" | |||
} | |||
}, | |||
"has-binary2": { | |||
"version": "1.0.3", | |||
"resolved": "https://registry.npmjs.org/has-binary2/-/has-binary2-1.0.3.tgz", | |||
"integrity": "sha512-G1LWKhDSvhGeAQ8mPVQlqNcOB2sJdwATtZKl2pDKKHfpf/rYj24lkinxf69blJbnsvtqqNU+L3SL50vzZhXOnw==", | |||
"requires": { | |||
"isarray": "2.0.1" | |||
} | |||
}, | |||
"has-cors": { | |||
"version": "1.1.0", | |||
"resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz", | |||
"integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk=" | |||
}, | |||
"indexof": { | |||
"version": "0.0.1", | |||
"resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz", | |||
"integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=" | |||
}, | |||
"isarray": { | |||
"version": "2.0.1", | |||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz", | |||
"integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4=" | |||
}, | |||
"mime-db": { | |||
"version": "1.39.0", | |||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.39.0.tgz", | |||
"integrity": "sha512-DTsrw/iWVvwHH+9Otxccdyy0Tgiil6TWK/xhfARJZF/QFhwOgZgOIvA2/VIGpM8U7Q8z5nDmdDWC6tuVMJNibw==" | |||
}, | |||
"mime-types": { | |||
"version": "2.1.23", | |||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.23.tgz", | |||
"integrity": "sha512-ROk/m+gMVSrRxTkMlaQOvFmFmYDc7sZgrjjM76abqmd2Cc5fCV7jAMA5XUccEtJ3cYiYdgixUVI+fApc2LkXlw==", | |||
"requires": { | |||
"mime-db": "1.39.0" | |||
} | |||
}, | |||
"ms": { | |||
"version": "2.1.1", | |||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", | |||
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" | |||
}, | |||
"negotiator": { | |||
"version": "0.6.1", | |||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", | |||
"integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" | |||
}, | |||
"object-component": { | |||
"version": "0.0.3", | |||
"resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz", | |||
"integrity": "sha1-8MaapQ78lbhmwYb0AKM3acsvEpE=" | |||
}, | |||
"parseqs": { | |||
"version": "0.0.5", | |||
"resolved": "https://registry.npmjs.org/parseqs/-/parseqs-0.0.5.tgz", | |||
"integrity": "sha1-1SCKNzjkZ2bikbouoXNoSSGouJ0=", | |||
"requires": { | |||
"better-assert": "1.0.2" | |||
} | |||
}, | |||
"parseuri": { | |||
"version": "0.0.5", | |||
"resolved": "https://registry.npmjs.org/parseuri/-/parseuri-0.0.5.tgz", | |||
"integrity": "sha1-gCBKUNTbt3m/3G6+J3jZDkvOMgo=", | |||
"requires": { | |||
"better-assert": "1.0.2" | |||
} | |||
}, | |||
"socket.io": { | |||
"version": "2.2.0", | |||
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-2.2.0.tgz", | |||
"integrity": "sha512-wxXrIuZ8AILcn+f1B4ez4hJTPG24iNgxBBDaJfT6MsyOhVYiTXWexGoPkd87ktJG8kQEcL/NBvRi64+9k4Kc0w==", | |||
"requires": { | |||
"debug": "4.1.1", | |||
"engine.io": "3.3.2", | |||
"has-binary2": "1.0.3", | |||
"socket.io-adapter": "1.1.1", | |||
"socket.io-client": "2.2.0", | |||
"socket.io-parser": "3.3.0" | |||
} | |||
}, | |||
"socket.io-adapter": { | |||
"version": "1.1.1", | |||
"resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-1.1.1.tgz", | |||
"integrity": "sha1-KoBeihTWNyEk3ZFZrUUC+MsH8Gs=" | |||
}, | |||
"socket.io-client": { | |||
"version": "2.2.0", | |||
"resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-2.2.0.tgz", | |||
"integrity": "sha512-56ZrkTDbdTLmBIyfFYesgOxsjcLnwAKoN4CiPyTVkMQj3zTUh0QAx3GbvIvLpFEOvQWu92yyWICxB0u7wkVbYA==", | |||
"requires": { | |||
"backo2": "1.0.2", | |||
"base64-arraybuffer": "0.1.5", | |||
"component-bind": "1.0.0", | |||
"component-emitter": "1.2.1", | |||
"debug": "3.1.0", | |||
"engine.io-client": "3.3.2", | |||
"has-binary2": "1.0.3", | |||
"has-cors": "1.1.0", | |||
"indexof": "0.0.1", | |||
"object-component": "0.0.3", | |||
"parseqs": "0.0.5", | |||
"parseuri": "0.0.5", | |||
"socket.io-parser": "3.3.0", | |||
"to-array": "0.1.4" | |||
}, | |||
"dependencies": { | |||
"debug": { | |||
"version": "3.1.0", | |||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", | |||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", | |||
"requires": { | |||
"ms": "2.0.0" | |||
} | |||
}, | |||
"ms": { | |||
"version": "2.0.0", | |||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", | |||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" | |||
} | |||
} | |||
}, | |||
"socket.io-parser": { | |||
"version": "3.3.0", | |||
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.3.0.tgz", | |||
"integrity": "sha512-hczmV6bDgdaEbVqhAeVMM/jfUfzuEZHsQg6eOmLgJht6G3mPKMxYm75w2+qhAQZ+4X+1+ATZ+QFKeOZD5riHng==", | |||
"requires": { | |||
"component-emitter": "1.2.1", | |||
"debug": "3.1.0", | |||
"isarray": "2.0.1" | |||
}, | |||
"dependencies": { | |||
"debug": { | |||
"version": "3.1.0", | |||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", | |||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", | |||
"requires": { | |||
"ms": "2.0.0" | |||
} | |||
}, | |||
"ms": { | |||
"version": "2.0.0", | |||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", | |||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" | |||
} | |||
} | |||
}, | |||
"to-array": { | |||
"version": "0.1.4", | |||
"resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz", | |||
"integrity": "sha1-F+bBH3PdTz10zaek/zI46a2b+JA=" | |||
}, | |||
"ws": { | |||
"version": "6.1.4", | |||
"resolved": "https://registry.npmjs.org/ws/-/ws-6.1.4.tgz", | |||
"integrity": "sha512-eqZfL+NE/YQc1/ZynhojeV8q+H050oR8AZ2uIev7RU10svA9ZnJUddHcOUZTJLinZ9yEfdA2kSATS2qZK5fhJA==", | |||
"requires": { | |||
"async-limiter": "1.0.0" | |||
} | |||
}, | |||
"xmlhttprequest-ssl": { | |||
"version": "1.5.5", | |||
"resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz", | |||
"integrity": "sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4=" | |||
}, | |||
"yeast": { | |||
"version": "0.1.2", | |||
"resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz", | |||
"integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=" | |||
} | |||
} | |||
} |
@ -0,0 +1 @@ | |||
Subproject commit 3020e455ab9a81341722e6c1e6cd8ef6b4b0ea28 |
@ -0,0 +1,16 @@ | |||
#userpic{ | |||
height: 150px; | |||
width: auto; | |||
border: black 1px solid; | |||
} | |||
.inline{ | |||
display: inline-block; | |||
} | |||
td{ | |||
padding: 0px 5px; | |||
} | |||
table, td { | |||
border: 1px solid black; | |||
} |
@ -0,0 +1,37 @@ | |||
import cv2 | |||
from pyzbar import pyzbar | |||
class Read(): | |||
instance = 0 | |||
sid = 0 | |||
def __init__(self,inst): | |||
self.instance = inst | |||
def detect(self): | |||
cam = cv2.VideoCapture(0) | |||
barcodeData_prev = 0 | |||
while 1: | |||
ret , img = cam.read() | |||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |||
barcode = pyzbar.decode(gray) | |||
if len(barcode) > 0: | |||
barcode = barcode[0] | |||
(x, y, w, h) = barcode.rect | |||
barcodeData = barcode.data.decode("utf-8") | |||
barcodeType = barcode.type | |||
if barcodeData_prev == 0 or barcodeData_prev != barcodeData: | |||
barcodeData_prev = barcodeData | |||
self.instance.received(barcodeData) | |||
continue | |||
text = "{} ({})".format(barcodeData, barcodeType) | |||
cv2.putText(img, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, | |||
0.5, (255, 0, 0), 2) | |||
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) | |||
cv2.imshow("a", img) | |||
if cv2.waitKey(1) & 0xFF == ord('q'): | |||
break | |||
cam.release() | |||
cv2.destroyAllWindows() |
@ -0,0 +1,30 @@ | |||
from multiprocessing import Process | |||
import reader | |||
class Reader(): | |||
def __init__(self): | |||
read = reader.Read(self) | |||
p1 = Process(target=read.detect) | |||
p1.start() | |||
def received(self,data): | |||
print(data) | |||
qr_reader = Reader() | |||
while 1: | |||
continue | |||
@ -0,0 +1 @@ | |||
pyzbar==0.1.8 |
@ -1,63 +1,367 @@ | |||
from flask import Flask, request | |||
from flask_restful import Resource, Api, abort | |||
import datetime | |||
import json | |||
import requests | |||
import json | |||
from flask import Flask, request | |||
from flask_restful import Api, Resource | |||
app = Flask( __name__ ) | |||
api = Api( app ) | |||
app = Flask(__name__) | |||
api = Api(app) | |||
bus_data = open("databases/bus.json","a") | |||
def sendRequest( url, raw ): | |||
def send_request(url, raw): | |||
headers = { | |||
"User-Agent": "EGO Genel Mudurlugu-EGO Cepte-3.1.0 GT-I9500 7.1.2", | |||
"Content-Type": "application/x-www-form-urlencoded", | |||
"Content-Length": "0" } | |||
headers[ "Content-Length" ] = str( len( raw ) ) | |||
r = requests.post( url, headers=headers, data=raw ) | |||
content = r.content.decode( "cp1252" ) | |||
content = content.replace( "Ý", "I" ) | |||
content = content.replace( "ý", "i" ) | |||
content = content.replace( "ð", "g" ) | |||
content = content.replace( "þ", "s" ) | |||
content = content.replace( "Þ", "S" ) | |||
"User-Agent": "EGO Genel Mudurlugu-EGO Cepte-3.1.0 GT-I9500 7.1.2", | |||
"Content-Type":"application/x-www-form-urlencoded", "Content-Length":str(len(raw)) | |||
} | |||
r = requests.post(url, headers=headers, data=raw) | |||
content = r.content.decode("cp1252") | |||
replace_chars = {"Ý":"I", "ý":"i", "ð":"g", "þ":"s", "Þ":"S"} | |||
for key in replace_chars: | |||
content.replace(key, replace_chars[key]) | |||
content = content.replace("'", '"') | |||
content = json.loads(content) | |||
return content | |||
conn1 = sendRequest( | |||
'http://88.255.141.70/mbl/android/connect.asp?SID=0.9672804113380772&VER=3.1.0&LAN=tr&UID=%7BACB78701' \ | |||
'-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Connect', | |||
"UID=%7BACB78701-2727-4E9A-AE62-28491D671A7D%7D-130570234&UPS=TRUE" ) | |||
conn2 = sendRequest( | |||
'http://88.255.141.66/mbl/android/connect.asp?SID=0.6654049014198404&VER=3.1.0&LAN=tr&UID=%7BACB78701' \ | |||
'-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Start', "" ) | |||
hatlar = sendRequest( 'http://88.255.141.66/mbl/android/action.asp?SID=0.8328642811845514&VER=3.1.0&LAN=tr&UID' | |||
'=%7BACB78701-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Hatlar', "QUERY=" ) | |||
hatlar = hatlar.replace( "'", '"' ) | |||
hatlar = json.loads( hatlar ) | |||
conn1 = send_request( | |||
'http://88.255.141.70/mbl/android/connect.asp?SID=0.392509188312098&VER=3.1.0&LAN=tr&UID=%7BACB78701' | |||
'-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Connect', | |||
"UID=%7BACB78701-2727-4E9A-AE62-28491D671A7D%7D-130570234&UPS=TRUE") | |||
conn2 = send_request( | |||
'http://88.255.141.66/mbl/android/connect.asp?SID=0.392509188312098&VER=3.1.0&LAN=tr&UID=%7BACB78701' | |||
'-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Start', "") | |||
bus_data = open("modules/databases/bus.json", "r") | |||
bus_json = json.loads(bus_data.read()) | |||
routes = bus_json["stops"] | |||
bus_data.close() | |||
print('\n', conn1, '\n\n', conn2, '\n') | |||
def time_small(t1, t2): | |||
time1 = datetime.datetime.strptime(t1, "%H:%M") | |||
time2 = datetime.datetime.strptime(t2, "%H:%M") | |||
if time1 < time2: | |||
return False | |||
else: | |||
return True | |||
def time_diff(t1, t2): | |||
time1 = datetime.datetime.strptime(t1, "%H:%M") | |||
time2 = datetime.datetime.strptime(t2, "%H:%M") | |||
response = "" | |||
if abs(time2.hour - time1.hour) < 10: | |||
response += "0" | |||
if time2.minute - time1.minute >= 0: | |||
response += str(abs(time2.hour - time1.hour)) | |||
else: | |||
response += str(abs(time2.hour - time1.hour) - 1) | |||
response += ":" | |||
if abs(time2.minute - time1.minute) < 10: | |||
response += "0" | |||
response += str(abs(time2.minute - time1.minute)) | |||
return response | |||
def time_sum(t1, t2): | |||
time1 = datetime.datetime.strptime(t1, "%H:%M") | |||
time2 = datetime.datetime.strptime(t2, "%H:%M") | |||
response = "" | |||
if time2.hour + time1.hour < 10: | |||
response += "0" | |||
if time2.minute + time1.minute > 60: | |||
response += str(time2.hour + time1.hour + 1) | |||
else: | |||
response += str(time2.hour + time1.hour) | |||
response += ":" | |||
if time2.minute + time1.minute % 60 < 10: | |||
response += "0" | |||
response += str((time2.minute + time1.minute) % 60) | |||
return response | |||
def get_closest_time(times, time): | |||
closest = [0, 0] | |||
for i in times[0]: | |||
if i.hour < time.hour or (i.hour == time.hour and i.minute - 6 < time.minute): | |||
continue | |||
else: | |||
if closest[0] == 0: | |||
closest[0] = i | |||
continue | |||
if abs(i.hour - time.hour) < abs(closest[0].hour - time.hour): | |||
closest[0] = i | |||
continue | |||
elif abs(i.hour - time.hour) == abs(closest[0].hour - time.hour): | |||
if i.minute - time.minute < closest[0].minute - time.minute: | |||
closest[0] = i | |||
if closest[0] == 0: | |||
return [] | |||
class Transit( Resource ): | |||
for i in times[1]: | |||
if i.hour < closest[0].hour or (i.hour == closest[0].hour and i.minute - 6 < closest[0].minute): | |||
continue | |||
else: | |||
if closest[1] == 0: | |||
closest[1] = i | |||
continue | |||
if abs(i.hour - time.hour) < abs(closest[1].hour - time.hour): | |||
closest[1] = i | |||
continue | |||
elif abs(i.hour - time.hour) == abs(closest[1].hour - time.hour): | |||
if i.minute - time.minute < closest[1].minute - time.minute: | |||
closest[1] = i | |||
if closest[1] == 0: | |||
return [] | |||
return [closest[0].strftime("%H:%M"), closest[1].strftime("%H:%M")] | |||
def post( self ): | |||
class Transit(Resource): | |||
def post(self): | |||
change = False | |||
args = request.form | |||
stops_raw = {"user":{}, "dest":{}} | |||
stops_arr = {"user":{}, "dest":{}} | |||
url_closestops = "http://88.255.141.66/mbl/android/action.asp?SID=0.392509188312098&VER=3.1.0&LAN=tr&UID"\ | |||
"=%7BACB78701"\ | |||
"-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=YakinDuraklar" | |||
closestops = send_request(url_closestops, "LAT={0}&LNG={1}&MSF=500".format(args["lat_usr"], args["lng_usr"])) | |||
for stop in closestops["data"][0]["table"]: | |||
stops_arr["user"][stop["kod"]] = stop["hatlar"].split(",") | |||
closestops = send_request(url_closestops, "LAT={0}&LNG={1}&MSF=500".format(args["lat_dest"], args["lng_dest"])) | |||
for stop in closestops["data"][0]["table"]: | |||
stops_arr["dest"][stop["kod"]] = stop["hatlar"].split(",") | |||
one_bus = {k.strip(): | |||
[dict({x:n for n in stops_arr["user"] for x in stops_arr["user"][n]})[k], | |||
dict({x:n for n in stops_arr["dest"] for x in stops_arr["dest"][n]})[k]] | |||
for k in (list(set([x for n in stops_arr["user"] for x in stops_arr["user"][n]]) | |||
& set([x for n in stops_arr["dest"] for x in stops_arr["dest"][n]])))} | |||
travel = {"routes":[], "total":[]} | |||
# time_cur = datetime.datetime.today().time() | |||
time_cur = datetime.datetime.strptime("13:00", "%H:%M") | |||
if len(one_bus) > 0: | |||
for i in one_bus: | |||
travel["routes"].append([{"name":i, "stops":[one_bus[i][0], one_bus[i][1]]}]) | |||
else: | |||
routes_arr = {"user":{}, "dest":{}} | |||
stopno = {} | |||
for i in stops_arr["user"]: | |||
for j in stops_arr["user"][i]: | |||
try: | |||
routes_arr["user"][j.strip()] = bus_json["stops"][j.strip()] | |||
except KeyError: | |||
stops = send_request( | |||
"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"] | |||
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: | |||
bus_json["stop_info"][x["kod"]] = { | |||
"name": x["ad"], | |||
"location":x["konum"], | |||
"lat": x["lat"], | |||
"lng": x["lng"] | |||
} | |||
change = True | |||
stopno[j.strip()] = i | |||
for i in stops_arr["dest"]: | |||
for j in stops_arr["dest"][i]: | |||
try: | |||
routes_arr["dest"][j.strip()] = bus_json["stops"][j.strip()] | |||
except KeyError: | |||
stops = send_request( | |||
"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"] | |||
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: | |||
bus_json["stop_info"][x["kod"]] = { | |||
"name": x["ad"], | |||
"location":x["konum"], | |||
"lat": x["lat"], | |||
"lng": x["lng"] | |||
} | |||
change = True | |||
stopno[j.strip()] = i | |||
for i in routes_arr["user"]: | |||
for j in routes_arr["user"][i]: | |||
for k in routes_arr["dest"]: | |||
for x in routes_arr["dest"][k]: | |||
if j.strip() == x.strip(): | |||
travel["routes"].append([ | |||
{"name":i.strip(), "stops":[stopno[i.strip()], x.strip()]}, | |||
{"name":k.strip(), "stops":[x.strip(), stopno[k.strip()]]}]) | |||
for i in range(len(travel["routes"])): | |||
for k in range(len(travel["routes"][i])): | |||
url = "http://88.255.141.66/mbl/android/action.asp?SID=0.4474110208361718&VER=3.1.0&LAN=tr&UID"\ | |||
"=%7BACB78701-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=DuraktanGecisSaatleri " | |||
weekno = datetime.datetime.today().weekday() | |||
times_anal = [[], []] | |||
for j in range(2): | |||
try: | |||
times_raw = bus_json["times"][travel["routes"][i][k]["name"]] | |||
except Exception: | |||
bus_json["times"][travel["routes"][i][k]["name"]] = {} | |||
try: | |||
times_raw = bus_json["times"][travel["routes"][i][k]["name"]][ | |||
travel["routes"][i][k]["stops"][j]] | |||
except Exception: | |||
bus_json["times"][travel["routes"][i][k]["name"]][travel["routes"][i][k]["stops"][j]] = {} | |||
if weekno < 5: | |||
try: | |||
weekday = "HAFTA+%C4%B0%C3%87%C4%B0" | |||
times_raw =\ | |||
bus_json["times"][travel["routes"][i][k]["name"]][travel["routes"][i][k]["stops"][j]][ | |||
"weekday"] | |||
except KeyError: | |||
bus_json["times"][travel["routes"][i][k]["name"]][travel["routes"][i][k]["stops"][j]][ | |||
"weekday"] = send_request(url, "HAT={0}&DURAK={1}&TUR={2}".format( | |||
travel["routes"][i][k]["name"], travel["routes"][i][k]["stops"][j], weekday))[ | |||
"data"][0]["table"] | |||
times_raw =\ | |||
bus_json["times"][travel["routes"][i][k]["name"]][travel["routes"][i][k]["stops"][j]][ | |||
"weekday"] | |||
change = True | |||
elif weekno == 5: | |||
try: | |||
weekday = "CUMARTES%C4%B0" | |||
times_raw =\ | |||
bus_json["times"][travel["routes"][i][k]["name"]][travel["routes"][i][k]["stops"][j]][ | |||
"saturday"] | |||
except KeyError: | |||
bus_json["times"][travel["routes"][i][k]["name"]][travel["routes"][i][k]["stops"][j]][ | |||
"saturday"] = send_request(url, "HAT={0}&DURAK={1}&TUR={2}".format( | |||
travel["routes"][i][k]["name"], travel["routes"][i][k]["stops"][j], weekday))[ | |||
"data"][0]["table"] | |||
times_raw =\ | |||
bus_json["times"][travel["routes"][i][k]["name"]][travel["routes"][i][k]["stops"][j]][ | |||
"saturday"] | |||
change = True | |||
else: | |||
try: | |||
weekday = "PAZAR" | |||
times_raw =\ | |||
bus_json["times"][travel["routes"][i][k]["name"]][travel["routes"][i][k]["stops"][j]][ | |||
"sunday"] | |||
except KeyError: | |||
bus_json["times"][travel["routes"][i][k]["name"]][travel["routes"][i][k]["stops"][j]][ | |||
"sunday"] = send_request(url, "HAT={0}&DURAK={1}&TUR={2}".format( | |||
travel["routes"][i][k]["name"], travel["routes"][i][k]["stops"][j], weekday))[ | |||
"data"][0]["table"] | |||
times_raw =\ | |||
bus_json["times"][travel["routes"][i][k]["name"]][travel["routes"][i][k]["stops"][j]][ | |||
"sunday"] | |||
change = True | |||
for time in times_raw: | |||
times_anal[j].append( | |||
datetime.datetime.strptime("{0}:{1}".format(time["saat"], time["dakika"]), "%H:%M")) | |||
closest_times = get_closest_time([times_anal[0], times_anal[1]], time_cur) | |||
travel["routes"][i][k]["time"] = closest_times | |||
empty = [] | |||
for i in range(len(travel["routes"])): | |||
remove = True | |||
for k in range(len(travel["routes"][i])): | |||
if remove: | |||
if len(travel["routes"][i][k]["time"]) == 0: | |||
empty.append(i - len(empty)) | |||
remove = False | |||
for i in empty: | |||
travel["routes"].pop(i) | |||
for route in travel["routes"]: | |||
start = route[0]["time"][0] | |||
end = route[-1]["time"][1] | |||
diff = time_diff(start, end) | |||
diff = time_sum(diff, time_diff(time_cur.strftime("%H:%M"), start)) | |||
diff = time_sum(diff, "00:05") | |||
travel["total"].append(diff) | |||
shortest = 0 | |||
durak = sendRequest( | |||
"http://88.255.141.66/mbl/android/service.asp?SID=0.09912588645045828&VER=3.1.0&LAN=tr&UID=%7BACB78701" \ | |||
"-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Otobusler", "DURAK=" + str( args[ "stop" ] ) ) | |||
durak = durak.replace( "'", '"' ) | |||
durak = json.loads( durak ) | |||
for i in range(len(travel["total"])): | |||
if shortest == 0: | |||
shortest = {"routes":travel["routes"][i], "time":travel["total"][i]} | |||
continue | |||
if time_small(shortest["time"], travel["total"][i]): | |||
shortest = {"routes":travel["routes"][i], "time":travel["total"][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 i in range(len(shortest["routes"])): | |||
try: | |||
shortest["routes"][i]["names"] = [bus_json["stop_info"][shortest["routes"][i][0]]["name"],bus_json["stop_info"][shortest["routes"][i][1]]["name"]] | |||
except KeyError: | |||
shortest["routes"][i]["names"] = [] | |||
shortest["routes"][i]["locations"] = [] | |||
shortest["routes"][i]["coordinates"] = [] | |||
for j in range(2): | |||
data = send_request("http://88.255.141.66/mbl/android/action.asp?SID=0.21893997000802157&VER=3.1.0&LAN=tr&UID=%7BACB78701-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Duraklar", | |||
"QUERY={}".format(shortest["routes"][i]["stops"][j]))["data"][0]["table"][0] | |||
bus_json["stop_info"][shortest["routes"][i]["stops"][j]] ={ | |||
"name": data["ad"], | |||
"location": data["konum"], | |||
"lat": data["lat"], | |||
"lng": data["lng"] | |||
} | |||
shortest["routes"][i]["names"].append(bus_json["stop_info"][shortest["routes"][i]["stops"][j]]["name"]) | |||
shortest["routes"][i]["locations"].append(bus_json["stop_info"][shortest["routes"][i]["stops"][j]]["location"]) | |||
shortest["routes"][i]["coordinates"].append({"lat":bus_json["stop_info"][shortest["routes"][i]["stops"][j]]["lat"], "lng":bus_json["stop_info"][shortest["routes"][i]["stops"][j]]["lng"]}) | |||
change=True | |||
return [durak,hatlar] | |||
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() | |||
return shortest | |||
if __name__ == '__main__': | |||
api.add_resource( Transit, '/transit', '/transit/' ) | |||
api.add_resource(Transit, '/transit', '/transit/') | |||
app.run( host='0.0.0.0', port=5000 ) | |||
app.run(host='0.0.0.0', port=5000) |
@ -1,60 +0,0 @@ | |||
# Created by .ignore support plugin (hsz.mobi) | |||
### JetBrains template | |||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm | |||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | |||
# User-specific stuff | |||
.idea/**/workspace.xml | |||
.idea/**/tasks.xml | |||
.idea/**/dictionaries | |||
.idea/**/shelf | |||
# Sensitive or high-churn files | |||
.idea/**/dataSources/ | |||
.idea/**/dataSources.ids | |||
.idea/**/dataSources.local.xml | |||
.idea/**/sqlDataSources.xml | |||
.idea/**/dynamic.xml | |||
.idea/**/uiDesigner.xml | |||
.idea/**/dbnavigator.xml | |||
# Gradle | |||
.idea/**/gradle.xml | |||
.idea/**/libraries | |||
# CMake | |||
cmake-build-debug/ | |||
cmake-build-release/ | |||
# Mongo Explorer plugin | |||
.idea/**/mongoSettings.xml | |||
# File-based project format | |||
*.iws | |||
# IntelliJ | |||
out/ | |||
# mpeltonen/sbt-idea plugin | |||
.idea_modules/ | |||
# JIRA plugin | |||
atlassian-ide-plugin.xml | |||
# Cursive Clojure plugin | |||
.idea/replstate.xml | |||
# Crashlytics plugin (for Android Studio and IntelliJ) | |||
com_crashlytics_export_strings.xml | |||
crashlytics.properties | |||
crashlytics-build.properties | |||
fabric.properties | |||
# Editor-based Rest Client | |||
.idea/httpRequests | |||
face/* | |||
hand/* | |||
pose/* | |||
cameraParameters/* | |||
cameraParameters/*/* |
@ -1,85 +0,0 @@ | |||
import cv2 | |||
import time | |||
import numpy as np | |||
MODE = "MPI" | |||
if MODE is "COCO": | |||
protoFile = "pose/coco/pose_deploy_linevec.prototxt" | |||
weightsFile = "pose/coco/pose_iter_440000.caffemodel" | |||
nPoints = 18 | |||
POSE_PAIRS = [ [1,0],[1,2],[1,5],[2,3],[3,4],[5,6],[6,7],[1,8],[8,9],[9,10],[1,11],[11,12],[12,13],[0,14],[0,15],[14,16],[15,17]] | |||
elif MODE is "MPI" : | |||
protoFile = "pose/mpi/pose_deploy_linevec_faster_4_stages.prototxt" | |||
weightsFile = "pose/mpi/pose_iter_160000.caffemodel" | |||
nPoints = 15 | |||
POSE_PAIRS = [[0,1], [1,2], [2,3], [3,4], [1,5], [5,6], [6,7], [1,14], [14,8], [8,9], [9,10], [14,11], [11,12], [12,13] ] | |||
frame = cv2.imread("single.jpeg") | |||
frameCopy = np.copy(frame) | |||
frameWidth = frame.shape[1] | |||
frameHeight = frame.shape[0] | |||
threshold = 0.2 | |||
net = cv2.dnn.readNetFromCaffe(protoFile, weightsFile) | |||
t = time.time() | |||
# input image dimensions for the network | |||
inWidth = 368 | |||
inHeight = 368 | |||
inpBlob = cv2.dnn.blobFromImage(frame, 1.0 / 255, (inWidth, inHeight), | |||
(0, 0, 0), swapRB=False, crop=False) | |||
net.setInput(inpBlob) | |||
output = net.forward() | |||
print("time taken by network : {:.3f}".format(time.time() - t)) | |||
H = output.shape[2] | |||
W = output.shape[3] | |||
# Empty list to store the detected keypoints | |||
points = [] | |||
for i in range(nPoints): | |||
# confidence map of corresponding body's part. | |||
probMap = output[0, i, :, :] | |||
# Find global maxima of the probMap. | |||
minVal, prob, minLoc, point = cv2.minMaxLoc(probMap) | |||
# Scale the point to fit on the original image | |||
x = (frameWidth * point[0]) / W | |||
y = (frameHeight * point[1]) / H | |||
if prob > threshold : | |||
cv2.circle(frameCopy, (int(x), int(y)), 8, (0, 255, 255), thickness=-1, lineType=cv2.FILLED) | |||
cv2.putText(frameCopy, "{}".format(i), (int(x), int(y)), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, lineType=cv2.LINE_AA) | |||
# Add the point to the list if the probability is greater than the threshold | |||
points.append((int(x), int(y))) | |||
else : | |||
points.append(None) | |||
# Draw Skeleton | |||
for pair in POSE_PAIRS: | |||
partA = pair[0] | |||
partB = pair[1] | |||
if points[partA] and points[partB]: | |||
cv2.line(frame, points[partA], points[partB], (0, 255, 255), 2) | |||
cv2.circle(frame, points[partA], 8, (0, 0, 255), thickness=-1, lineType=cv2.FILLED) | |||
cv2.imshow('Output-Keypoints', cv2.resize(frameCopy,(900,900))) | |||
cv2.imshow('Output-Skeleton', cv2.resize(frame,(600,900))) | |||
cv2.imwrite('Output-Keypoints.jpg', frameCopy) | |||
cv2.imwrite('Output-Skeleton.jpg', frame) | |||
print("Total time taken : {:.3f}".format(time.time() - t)) | |||
cv2.waitKey(0) |
@ -1,15 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<module type="WEB_MODULE" version="4"> | |||
<component name="FacetManager"> | |||
<facet type="Python" name="Python"> | |||
<configuration sdkName="Python 3.7" /> | |||
</facet> | |||
</component> | |||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |||
<exclude-output /> | |||
<content url="file://$MODULE_DIR$" /> | |||
<orderEntry type="inheritedJdk" /> | |||
<orderEntry type="sourceFolder" forTests="false" /> | |||
<orderEntry type="library" name="Python 3.7 interpreter library" level="application" /> | |||
</component> | |||
</module> |