Skip to content
Browse files

minor

  • Loading branch information...
1 parent 4a3c08c commit c1ce35abe91c38d4e5fc1080b55941ec1d0a779b will committed Dec 8, 2009
Showing with 56 additions and 34 deletions.
  1. +3 −17 models.py
  2. +53 −17 reports.py
View
20 models.py
@@ -26,27 +26,13 @@
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base(metadata=metadata)
-__all__ = ['Anopheline', 'Anopheline2', 'Source', 'Site', 'SiteCoordinates', 'ExpertOpinion', 'SamplePeriod', 'SitePresenceAbsenceView', 'SpeciesExtentView', 'SamplePeriodPresenceAbsenceView','Session', 'World', 'Map', 'Collection', 'Identification','CollectionMethod', 'IdentificationMethod', 'Region','TagComment',]
+__all__ = ['Anopheline2', 'Source', 'Site', 'SiteCoordinates', 'ExpertOpinion', 'SamplePeriod', 'SitePresenceAbsenceView', 'SpeciesExtentView', 'SamplePeriodPresenceAbsenceView','Session', 'World', 'Map', 'Collection', 'Identification','CollectionMethod', 'IdentificationMethod', 'Region','TagComment',]
"""
Views are used extensively here:
vector_sampleperiod_presence_absence excludes unreliable records and checks for presence / absence.
"""
-class Anopheline(Base):
- """
- """
- __tablename__ = "vector_anopheline"
- id = Column(Integer, primary_key=True)
- name = Column(String)
- abbreviation = Column(String)
- sub_genus = Column(String)
- species = Column(String)
- author = Column(String)
- is_complex = Column(Boolean)
- def __repr__(self):
- return self.name
-
class Anopheline2(Base):
"""
"""
@@ -97,6 +83,7 @@ class ExpertOpinion(Base):
geom = Column(Geometry(4326))
anopheline2_id = Column(Integer, ForeignKey('vector_anopheline2.id'))
anopheline2 = relation(Anopheline2, backref="expert_opinion")
+ reference = Column(String)
class SamplePeriodView(Base):
__table__ = Table('vector_sampleperiod_site_presence_absence', metadata, Column('id', Integer(), primary_key=True), autoload=True)
@@ -138,8 +125,6 @@ class SamplePeriod(Base):
site_id = Column(Integer, ForeignKey('site.site_id'))
source_id = Column(Integer, ForeignKey('source.enl_id'))
complex = Column(String)
- anopheline_id = Column(Integer, ForeignKey('vector_anopheline.id'))
- anopheline = relation(Anopheline, backref="sample_period")
anopheline2_id = Column(Integer, ForeignKey('vector_anopheline2.id'))
anopheline2 = relation(Anopheline2, backref="sample_period")
start_month = Column(Integer, nullable=True)
@@ -192,6 +177,7 @@ def expand(self, proportion):
self.miny = self.miny - (dY * proportion)
self.maxy = self.maxy + (dY * proportion)
+#FIXME: keep data and display separate!
class LayerStyle(Base):
__tablename__ = "vector_layerstyle"
id = Column(Integer, primary_key=True)
View
70 reports.py
@@ -1,6 +1,6 @@
from sqlalchemy.orm import join
from sqlalchemy.sql import func, exists, and_, not_
-from models import Anopheline, Site, SamplePeriod, Session
+from models import Session
from sqlalchemygeom import *
session = Session(autocommit=True)
@@ -34,22 +34,6 @@ def __init__(self, title, query, headers=None, totals=None):
self.headers = headers
self.totals = totals
-sampleperiod_subq = session.query(
- SamplePeriod.anopheline2_id,
- func.count(func.distinct(SamplePeriod.site_id)).label('site_count'),
- func.count('*').label('sampleperiod_count')
- ).group_by(SamplePeriod.anopheline2_id).subquery()
-
-point_subq = session.query(
- SamplePeriod.anopheline2_id,
- func.count('*').label('count')
- ).filter(Site.area_type=='point').filter(exists().where(SamplePeriod.site_id==Site.site_id)).filter(Anopheline.id==SamplePeriod.anopheline2_id)
-
-q = session.query(Anopheline.name,
- func.coalesce(sampleperiod_subq.c.site_count,0),
- func.coalesce(sampleperiod_subq.c.sampleperiod_count, 0)
- ).order_by(Anopheline.name.desc())
-
#reports.append(
# ExcelReport(
# 'Sundaicus',
@@ -82,6 +66,15 @@ def __init__(self, title, query, headers=None, totals=None):
reports.append(
ExcelReport(
+ 'Lesterii',
+ """
+ SELECT source_id, site_id, id from vector_sampleperiod where notes ilike '%lesteri%' order by 1,2,3;
+ """,
+ headers = ["source_id", "site_id", "sampleperiod_id",]
+ )
+)
+reports.append(
+ ExcelReport(
'Sites and sample periods by all species',
"""
select (select abbreviation from vector_anopheline2 va where va.id = vector_sampleperiod.anopheline2_id),count(distinct(site_id)), count(*) from vector_sampleperiod where anopheline2_id != 8 group by anopheline2_id order by 1
@@ -93,6 +86,49 @@ def __init__(self, title, query, headers=None, totals=None):
reports.append(
ExcelReport(
+ 'Polygonal sites',
+ """
+ SELECT distinct vsp.source_id, site.site_id, site.full_name, site.area_type
+ from site
+ join vector_sampleperiod vsp
+ on site.site_id = vsp.site_id
+ where area_type in ('polygon', 'polygon large', 'polygon large')
+ ;
+ """,
+
+ headers = ["source_id", "site_id", "full_name ", "area_type",]
+ )
+)
+
+reports.append(
+ ExcelReport(
+ 'Non-georeferenced sites',
+ """
+ SELECT distinct vsp.source_id, site.site_id, site.full_name, site.area_type
+ from site
+ join vector_sampleperiod vsp
+ on site.site_id = vsp.site_id
+ where not exists(select * from site_coordinates sc where sc.site_id = site.site_id)
+ ;
+ """,
+
+ headers = ["source_id", "site_id", "full_name ", "area_type",]
+ )
+)
+
+reports.append(
+ ExcelReport(
+ 'Geopositions',
+ """
+ select * from site_geopositions
+ """,
+
+ headers = ["vector_source_id", "pr_source_id", "Country ", "Admin1", "Admin2", "Site", "Lat", "Long", "Latlong_source", "Site_notes", " AREA_TYPE", " Site_ID", "Good guess", " Rough guess",]
+ )
+)
+
+reports.append(
+ ExcelReport(
'Sites and sample periods by 41 DVS',
"""
SELECT

0 comments on commit c1ce35a

Please sign in to comment.
Something went wrong with that request. Please try again.