Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
286e2e1
add 'to do list' using docker-compose, flask, mongo
Adusei Oct 6, 2017
916b82c
move app py files into api directory
Adusei Oct 6, 2017
ab8d17e
trying two react native boilerplates
Adusei Oct 6, 2017
f84df36
combine two approaches in hello-world react app
Adusei Oct 6, 2017
38fdf26
rm 2 old react apps
Adusei Oct 6, 2017
3eec7b5
add two apps, one native, one web add hot loading on web
Adusei Oct 7, 2017
68fbbc9
adding some actions / reducers
Adusei Oct 7, 2017
5bb2106
put the node process in docker compose
Adusei Oct 7, 2017
fcec321
get spongemap.html in app.js
Adusei Oct 10, 2017
824dc9d
split python template file into components
Adusei Oct 10, 2017
3639a0f
render a leaflet map
Adusei Oct 10, 2017
050dea0
after wresting with axios cors errors, use jsonp package
Adusei Oct 12, 2017
d086a1e
trying different leaflet approaches
Adusei Oct 12, 2017
b227920
cleanup, add back the pure leaflet implementation
Adusei Oct 12, 2017
1277225
cleanup
Adusei Oct 13, 2017
f8817e9
working on installing carto
Adusei Oct 13, 2017
66fcec7
working on the AI import
Adusei Oct 13, 2017
4dc8769
use create viz as opposed to leaflet directly
Adusei Oct 13, 2017
5a32d1e
clean up cartowrapper to use just carto, not leaflet
Adusei Oct 13, 2017
6a39fed
add boostrap for better layout
Adusei Oct 13, 2017
d85d257
cleanup
Adusei Oct 13, 2017
9da4565
add hide button for info panel
Adusei Oct 13, 2017
37a9d8e
cleanup, remove div i dont need
Adusei Oct 13, 2017
6bf28b7
cleanup indentation
Adusei Oct 16, 2017
f4ae582
add first unit test, mock AI call for faster development/debugging
Adusei Oct 16, 2017
0bd4425
working through ai api
Adusei Oct 17, 2017
857ad5c
replace get-or create with a DoesNotExist exception
Adusei Oct 18, 2017
9beb397
set up api..
Adusei Oct 18, 2017
33d0ef1
use redux to hide info panel
Adusei Oct 20, 2017
174eba2
using redux constructs to manipulate state
Adusei Oct 20, 2017
31a8d05
try/catch around everything that failed in ingesting data
Adusei Oct 20, 2017
4da2e1e
set up redux to pass state from nav control to map component
Adusei Oct 22, 2017
3ec0b06
turn active layers into an object to find the state difference
Adusei Oct 27, 2017
2683402
add and remove layers with checkboxes
Adusei Oct 27, 2017
b0a7df3
Update README.md formatting
wildmolasses Mar 13, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AI_DBS=test
AI_USERNAME=test
AI_PASSWORD=test
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
*idea*

*.pyc

*.db

*.box

.vagrant
.vagrant
venv
*node_modules/
*.DS_Store
.env
api/test/fixtures/
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# SpongeBase
Interactive data mash-up of Lebanon's locations and interventions
Interactive data mash-up of Lebanon's locations and interventions

A joint project by UNHCR/UNICEF Innovation leads in Lebanon.

##Project overview
## Project overview

Data on geographical locations (governorates, districts, cities, villages, camps, schools etc…) in a humanitarian response is often scattered in different locations, whether in databases, folders, assessment reports, and information sharing websites. A lot of effort is spent on collating available information for secondary data reviews as well as for profiling certain geographical location for operational importance.
The idea of this project is to automatically collate available information from different data sources in a simple format and linking them to a geographical location like a governorate, district, village or even a small camp.
SpongeBase is composed of a dynamic map interface (SpongeMap) and a web app/interface (DOG).
Data on geographical locations (governorates, districts, cities, villages, camps, schools etc…) in a humanitarian response is often scattered in different locations, whether in databases, folders, assessment reports, and information sharing websites. A lot of effort is spent on collating available information for secondary data reviews as well as for profiling certain geographical location for operational importance.
The idea of this project is to automatically collate available information from different data sources in a simple format and linking them to a geographical location like a governorate, district, village or even a small camp.
SpongeBase is composed of a dynamic map interface (SpongeMap) and a web app/interface (DOG).

SpongeMap has only the Common and Fundamental Operational Data Sets (CoDs and FoDs) preloaded. The DOG is a web application and web API that links to existing information systems and remote folders (like Dropbox). Sponemap sends a request for information regarding a certain location and the DOG fetches all available information even from excel files in dropbox folders, packages it and sends it back to be displayed on the map.
Not only will this project help collating information but it has the potential to revolutionize the way we look at Who What Where (3W) information. Partners would fill a simple template, store it in a dropbox and the information becomes available to other actors on a map and all in one simple readable format. Agencies wanting to work in a specific area would go to the map, zoom in to a location and retrieve key information whether population figures, key indicators, implemented projects, or major/minor events or issues that happened in that location. With all this knowledge base, agencies would then decide if this is an area that requires their intervention.
Not only will this project help collating information but it has the potential to revolutionize the way we look at Who What Where (3W) information. Partners would fill a simple template, store it in a dropbox and the information becomes available to other actors on a map and all in one simple readable format. Agencies wanting to work in a specific area would go to the map, zoom in to a location and retrieve key information whether population figures, key indicators, implemented projects, or major/minor events or issues that happened in that location. With all this knowledge base, agencies would then decide if this is an area that requires their intervention.


## Code

### Get in to docker containers

61d103150e85
18 changes: 18 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:2.7-alpine
ADD . /todo
WORKDIR /todo
RUN pip install -r requirements.txt

## cron ##

# Add crontab file in the cron directory
## ADD crontab /etc/cron.d/hello-cron

# Give execution rights on the cron job
## RUN chmod 0644 /etc/cron.d/hello-cron

# Create the log file to be able to run tail
## RUN touch /var/log/cron.log

# # Run the command on container startup
# CMD cron && tail -f /var/log/cron.log
7 changes: 7 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
If you don't want to run this in docker, run:

`$ virtualenv venv`

`$ venv`

we want to go back to equitrip
132 changes: 132 additions & 0 deletions api/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import os

from flask import Flask, redirect, url_for, request, render_template
from flask_mongorest import methods
from flask_mongorest.views import ResourceView
from flask_mongorest.resources import Resource
from pymongo import MongoClient
from flask_mongorest import MongoRest
from flask_mongorest import methods
from flask_mongorest import operators as ops

from spongemap import ReportResource

from flask_mongoengine import MongoEngine

# Create application
app = Flask(__name__)

app.config['DEBUG'] = True

# Create dummy secrey key so we can use sessions
app.config['SECRET_KEY'] = '123456790'
app.config['MONGODB_SETTINGS'] = {
'db': 'ai-aggregator',
'host': ['DB_PORT_27017_TCP_ADDR'],
'port': 27017
}
db = MongoEngine()
api = MongoRest(app)

@app.route('/')
def index():
return render_template('spongemap.html')


class Attribute(db.EmbeddedDocument):
name = db.StringField()
value = db.StringField()

class NeNone(ops.Ne):
def apply(self, queryset, field, value, negate=False):
# convert nulls to python None
if value == u'null':
value = None
return super(NeNone, self).apply(queryset, field, value)


class AttributeResource(Resource):
document = Attribute

class Report(db.Document):
db_name = db.StringField()
date = db.StringField()
site_id = db.IntField()
p_code = db.StringField()
category = db.StringField()
activity_id = db.IntField()
activity = db.StringField()
partner_id = db.IntField()
partner_name = db.StringField()
location_id = db.IntField()
location_name = db.StringField()
location_type = db.StringField()
location_x = db.DecimalField()
location_y = db.DecimalField()
gov_code = db.StringField()
governorate = db.StringField()
district_code = db.StringField()
district = db.StringField()
cadastral_code = db.StringField()
cadastral = db.StringField()
indicator_id = db.IntField()
indicator_category = db.StringField()
indicator_name = db.StringField()
value = db.DecimalField()
units = db.StringField()
comments = db.StringField()
attributes = db.ListField(
db.EmbeddedDocumentField(Attribute)
)

meta = {
'indexes': [
'date',
'db_name',
'p_code',
'category',
'activity',
'partner_name',
'location_name',
'indicator_category',
'indicator_name',
'gov_code',
'governorate',
'district_code',
'district',
'cadastral_code',
'cadastral'
]
}


class ReportResource(Resource):
paginate = False
document = Report
related_resources = {
'attributes': AttributeResource,
}
filters = {
'p_code': [NeNone, ops.Exact, ops.Startswith],
'partner_name': [ops.Exact, ops.IStartswith, ops.IContains],
'db_name': [ops.Exact, ops.IStartswith, ops.IContains],
'date': [ops.Exact, ops.IStartswith, ops.IContains],
'category': [ops.Exact, ops.IStartswith, ops.IContains],
'activity': [ops.Exact, ops.IStartswith, ops.IContains],
'location_name': [ops.Exact, ops.IStartswith, ops.IContains],
'indicator_name': [ops.Exact, ops.IStartswith, ops.IContains],
'governorate': [ops.Exact, ops.IStartswith, ops.IContains],
'district': [ops.Exact, ops.IStartswith, ops.IContains],
'cadastral': [ops.Exact, ops.IStartswith, ops.IContains],
'cadastral_code': [ops.Exact, ops.IStartswith, ops.IContains],
}


@api.register(name='reports', url='/reports/')
class ReportsView(ResourceView):
resource = ReportResource
methods = [methods.List]


if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)
19 changes: 12 additions & 7 deletions requirements.txt → api/full-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
## flask stuff ##
Flask
Flask-OAuthlib
Flask-Views
Flask-Script
Flask-MongoEngine
flask-login
flask-admin
git+https://github.com/jamescw/flask-mongorest.git
git+https://github.com/HCDX/ActvityInfoPython.git
gunicorn

## 3rd party data producers stuff ##
activityinfo-python==1.6.0
cartodb
pandas
cleancat
mimerender

## stuff i woud like to remove ##
git+https://github.com/jamescw/flask-mongorest.git

## gunicorn
## cleancat
## mimerender
raven[flask]
requests
celery
redis
newrelic
DateTime
DateTime
Loading