lass="lines-code">
+    hospital_file  = models.FileField(upload_to="uploads/%Y/%m/%d/", blank=True, verbose_name="Hospital (csv)")
162
+
163
+    def save(self, *args, **kwargs):
164
+        super(ImportFile, self).save(*args, **kwargs)
165
+
166
+        with self.hospital_file.open('r') as csv_file:
167
+            csv_reader = csv.reader(csv_file, delimiter=',')
168
+            Hospital.objects.all().delete()
169
+            line_count = 0
170
+
171
+            for r in csv_reader:
172
+                if line_count > 0:
173
+                    print(r)
174
+                    print(f"{r[7]},{r[6]}")
175
+                    try:
176
+                        gp = map_fields.GeoPt(lat=float(r[6]), lon=float(r[7]))
177
+
178
+                        location = fromstr(f'POINT({r[7]} {r[6]})', srid=4326)
179
+                        print(location)
180
+                        h = Hospital(title=r[3], address_text=r[5], geolocation=gp, address=r[3])
181
+                        h.save()
182
+                    except Exception as e:
183
+                        print(e)
184
+
185
+                line_count += 1
186
+
187
+
188
+
127 189
 class Place(models.Model):
190
+    #title  = models.Char
191
+    title = models.CharField(max_length=200, blank=True, null=True)
128 192
     address = map_fields.AddressField(max_length=200)
129 193
     geolocation = map_fields.GeoLocationField(max_length=100)
130 194
 
@@ -133,6 +197,36 @@ class Place(models.Model):
133 197
 
134 198
     more_info  = models.JSONField(null=True, blank=True)
135 199
 
200
+    def __str__(self):
201
+        return f"{self.address} ({self.geolocation})"
202
+class Points(models.Model):
203
+    #src  = models.ForeignKey(Place, on_delete=models.SET_NULL, null=True, blank=False, related_name='src')
204
+    dest  = models.ForeignKey(Place, on_delete=models.SET_NULL, null=True, blank=False, related_name='dest')
205
+    address = map_fields.AddressField(max_length=200, null=True)
206
+    geolocation = map_fields.GeoLocationField(max_length=100, null=True)
207
+
208
+    distance = models.DecimalField(null=True, blank=True, decimal_places=2, max_digits=7, verbose_name="Distance (km)")
209
+    duration = models.CharField(max_length=200, null=True, blank=True)
210
+
211
+    directions  = models.JSONField(null=True, blank=True)
212
+
213
+    def save(self, *args, **kwargs):
214
+        geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
215
+        print(geocode_result)
216
+        print(self.geolocation)
217
+        origin = [(self.geolocation.lat, self.geolocation.lon)]
218
+        dest = [(self.dest.geolocation.lat, self.dest.geolocation.lon)]
219
+        dst = gmaps.distance_matrix(origin, dest)
220
+        dirs = gmaps.directions(origin[0], dest[0])
221
+        self.directions = dirs
222
+        print(dirs)
223
+        self.distance = dst['rows'][0]['elements'][0]['distance']['value'] / 1000
224
+        self.duration = dst['rows'][0]['elements'][0]['duration']['text']
225
+        print(dst)
226
+        super(Points, self).save(*args, **kwargs)
227
+
228
+
229
+
136 230
 class Hospital(models.Model):
137 231
     title = models.CharField(max_length=200)
138 232
     location = models.PointField(blank=True, null=True)
@@ -190,3 +284,5 @@ class PatientLog(models.Model):
190 284
     updated_at = models.DateTimeField(auto_now=True)
191 285
 
192 286
 
287
+
288
+

+ 7 - 0
app/backend/templates/backend/import_file.html

@@ -0,0 +1,7 @@
1
+{% extends "base.html" %}
2
+
3
+{% block title %}My amazing blog{% endblock %}
4
+
5
+{% block content %}
6
+Import File
7
+{% endblock %}

+ 8 - 0
app/backend/templates/backend/index.html

@@ -0,0 +1,8 @@
1
+{% extends "base.html" %}
2
+
3
+{% block title %}My amazing blog{% endblock %}
4
+
5
+{% block content %}
6
+Hello world
7
+<a href="{% url "import_file" %}">Import</a>
8
+{% endblock %}

backend/tests.py → app/backend/tests.py


+ 1 - 0
backend/urls.py

@@ -4,4 +4,5 @@ from . import views
4 4
 
5 5
 urlpatterns = [
6 6
     path('', views.index, name='index'),
7
+    path('import_file', views.import_file, name='import_file'),
7 8
 ]

+ 11 - 0
app/backend/views.py

@@ -0,0 +1,11 @@
1
+from django.shortcuts import render
2
+
3
+# Create your views here.
4
+from django.http import HttpResponse
5
+
6
+
7
+def index(request):
8
+    return render(request, 'backend/index.html')
9
+
10
+def import_file(request):
11
+    return render(request, 'backend/import_file.html')

manage.py → app/manage.py


uploads/2021/07/18/67224.jpg → app/media/uploads/2021/07/18/67224.jpg


File diff suppressed because it is too large
+ 10715 - 0
app/media/uploads/2021/07/22/citizeninfo_health_20200314.csv


File diff suppressed because it is too large
+ 10715 - 0
app/media/uploads/2021/07/22/citizeninfo_health_20200314_W9jk8Vu.csv


+ 1 - 0
requirements.txt

@@ -5,3 +5,4 @@ django-smart-selects
5 5
 django-colorfield
6 6
 googlemaps
7 7
 django-json-widget
8
+django-import-export

backend/__init__.py → app/shaqfindbed/__init__.py


shaqfindbed/__pycache__/__init__.cpython-39.pyc → app/shaqfindbed/__pycache__/__init__.cpython-39.pyc


BIN
app/shaqfindbed/__pycache__/settings.cpython-39.pyc


BIN
shaqfindbed/__pycache__/urls.cpython-39.pyc


shaqfindbed/__pycache__/wsgi.cpython-39.pyc → app/shaqfindbed/__pycache__/wsgi.cpython-39.pyc


shaqfindbed/asgi.py → app/shaqfindbed/asgi.py


+ 3 - 2
shaqfindbed/settings.py

@@ -33,12 +33,13 @@ ALLOWED_HOSTS = []
33 33
 # Application definition
34 34
 
35 35
 INSTALLED_APPS = [
36
+    'django.contrib.staticfiles',
36 37
     'django.contrib.admin',
37 38
     'django.contrib.auth',
38 39
     'django.contrib.contenttypes',
39 40
     'django.contrib.sessions',
40 41
     'django.contrib.messages',
41
-    'django.contrib.staticfiles',
42
+    'import_export',
42 43
     'django_google_maps',
43 44
     'django.contrib.gis',
44 45
     'smart_selects',
@@ -62,7 +63,7 @@ ROOT_URLCONF = 'shaqfindbed.urls'
62 63
 TEMPLATES = [
63 64
     {
64 65
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
65
-        'DIRS': [],
66
+        'DIRS': [os.path.join(BASE_DIR, 'templates')],
66 67
         'APP_DIRS': True,
67 68
         'OPTIONS': {
68 69
             'context_processors': [

+ 1 - 1
shaqfindbed/urls.py

@@ -23,7 +23,7 @@ urlpatterns = [
23 23
     path('backend/', include('backend.urls')),
24 24
     path('admin/', admin.site.urls),
25 25
     url(r'^chaining/', include('smart_selects.urls')),
26
-]
26
+] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
27 27
 
28 28
 if settings.DEBUG:
29 29
     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

shaqfindbed/wsgi.py → app/shaqfindbed/wsgi.py


BIN
app/static/.DS_Store


BIN
app/static/admin/.DS_Store


staticfile/admin/css/autocomplete.css → app/static/admin/css/autocomplete.css


+ 0 - 0
staticfile/admin/css/base.css


Some files were not shown because too many files changed in this diff

tum/OBAppSrc - Gogs: Simplico Git Service

暫無描述

WebAppConnector.cs 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.IO;
  7. using Newtonsoft.Json.Linq;
  8. namespace WpfApplication19
  9. {
  10. class WebAppConnector
  11. {
  12. private WebRequest request;
  13. public string PostData { get; set; }
  14. public string Uri { get; set; }
  15. public string Method { get; set; }
  16. public Response sendRequest()
  17. {
  18. Response r = new Response();
  19. WebRequest request = WebRequest.Create(this.Uri);
  20. request.Method = this.Method;
  21. byte[] byteArray = Encoding.UTF8.GetBytes(this.PostData);
  22. request.ContentType = "application/x-www-form-urlencoded";
  23. request.ContentLength = byteArray.Length;
  24. Stream dataStream = request.GetRequestStream();
  25. dataStream.Write(byteArray, 0, byteArray.Length);
  26. dataStream.Close();
  27. WebResponse response = request.GetResponse();
  28. //Console.WriteLine(((HttpWebResponse)response).StatusDescription);
  29. r.status = ((HttpWebResponse)response).StatusDescription.Trim();
  30. dataStream = response.GetResponseStream();
  31. StreamReader reader = new StreamReader(dataStream);
  32. string responseFromServer = reader.ReadToEnd();
  33. //Console.WriteLine(responseFromServer);
  34. JObject o = JObject.Parse(responseFromServer);
  35. //Console.WriteLine(o["msg"]);
  36. r.jsonBody = o;
  37. reader.Close();
  38. dataStream.Close();
  39. response.Close();
  40. //Console.ReadLine();
  41. return r;
  42. }
  43. }
  44. class Response
  45. {
  46. public string status;
  47. public JObject jsonBody;
  48. }
  49. }