Ejemplo n.º 1
0
    def processRegionBAsed(self, region, start_date, end_date,
                           isCleaningRequired, parameters, monthly,
                           monthStartDate, monthEndDate, yearly, startYear,
                           endYear):
        results = []
        print("This is regionbased qp calculation for web service  data")
        obj = RegionData()
        # print obj.getAllRegionInfo()
        data = obj.getSingleRegionInfo(region)
        stationsInfo = data['data']['Stations']
        stations = []
        for stationdata in stationsInfo:
            station = stationdata['StationName']
            print("/n calculating parameters for station", station)
            result = self.processStationBased(region, station, start_date,
                                              end_date, isCleaningRequired,
                                              parameters, monthly,
                                              monthStartDate, monthEndDate,
                                              yearly, startYear, endYear)
            print result["Result"][0]
            results.append(result["Result"][0])

        print("/n result for all stations in the given region is: ", {
            'ModelBasedSubType': 'RegionBased',
            'Result': results
        })

        return {'ModelBasedSubType': 'RegionBased', 'Result': results}
Ejemplo n.º 2
0
def getRegionInformation():
    obj = RegionData()
    data = obj.getAllRegionInfo()
    otherStationItem = {'Lat': 0, 'StationCode': 'Other', 'Lon': 0, 'StationName': 'Other'};
    for item in data:
        item['Stations'].append(otherStationItem)
    # return data
    return jsonify({"regions":json.loads(dumps(data))})
Ejemplo n.º 3
0
    def getDatafromWebService(self, region, station, start_date, end_date):
        """
        This function is used to collect the data from National Oceanic and Atmospheric Administration
        :param stationcode:
        :param startdate:
        :param enddate:
        :return:
        """
        #construct filename in the format "region_station_startdate_enddate.json" with no spaces and "-"

        filename = region + "_" + station + "_" + start_date + "_" + end_date + ".json"
        filename = filename.replace(" ", "")
        filename = filename.replace("-", "")
        print filename
        obj = RegionData()
        stationcode = obj.getStaionCode(region, station)

        server = SOAPpy.SOAPProxy(
            "http://cdmo.baruch.sc.edu/webservices2/requests.cfc?wsdl")

        stationcode = "pdbjewq"
        responsedata = server.exportAllParamsDateRangeXMLNew(
            stationcode, start_date, end_date, '*')
        # print responsedata
        pythonObject = SOAPpy.Types.simplify(responsedata)
        #jsonObject = json.dumps(pythonObject)
        #assert type(jsonObject) == str
        dataArray = pythonObject["returnData"][
            "data"]  # returns {  [{...},{....},.....]}
        #print dataArray

        self.dataToJson(dataArray, filename)  # store the data into a json file
        #store data into rawdata collection

        rawObj = RawData()
        rawObj.insertRawStationData(region, station, start_date, end_date,
                                    dataArray)
        return filename  # return the json filename where data is stored
Ejemplo n.º 4
0
    def getDatafromWebService(self,region, station, start_date, end_date):
        """
        This function is used to collect the data from National Oceanic and Atmospheric Administration
        :param stationcode:
        :param startdate:
        :param enddate:
        :return:
        """
        #construct filename in the format "region_station_startdate_enddate.json" with no spaces and "-"
        """
        filename = region + "_" + station+ "_" + start_date + "_" + end_date + ".json"
        filename = filename.replace(" ","")
        filename = filename.replace("-","")
        print ("filename: "+filename)
        """
        #date format for getting data from web service = yy/mm/dd
        obj =  RegionData()
        stationcode = obj.getStaionCode(region, station)
        newStart_Date = datetime.datetime.strptime(start_date, "%m/%d/%Y").strftime("%Y-%m-%d")
        newEnd_Date = datetime.datetime.strptime(end_date, "%m/%d/%Y").strftime("%Y-%m-%d")

        server = SOAPpy.SOAPProxy("http://cdmo.baruch.sc.edu/webservices2/requests.cfc?wsdl")

        #stationcode="pdbjewq"
        responsedata =  server.exportAllParamsDateRangeXMLNew(stationcode, newStart_Date, newEnd_Date,'*')
        #responsedata = server.exportAllParamsDateRangeXMLNew('pdbjewq','2014-12-30', '2014-12-31', '*')

       # print responsedata
        pythonObject = SOAPpy.Types.simplify(responsedata)
        #jsonObject = json.dumps(pythonObject)
        #assert type(jsonObject) == str
        dataArray =  pythonObject["returnData"]["data"] # returns {  [{...},{....},.....]}

        #data from webservice has date format  mm/dd/yy = 12/31/2014
        #print(dataArray)

        return json.dumps(dataArray)
        """
Ejemplo n.º 5
0
        {
            'station': "Ploeg Channel",
            'code': "pdbbpwq",
            'lat': "48.556322",
            'lng': "122.530894"
        },
        {
            'station': "Joe Leary Estuary",
            'code': "pdbjewq",
            'lat': "48.518264",
            'lng': "122.474189"
        },
    ]
}

obj = RegionData()

server = SOAPpy.SOAPProxy(
    "http://cdmo.baruch.sc.edu/webservices2/requests.cfc?wsdl")
responsedata = server.exportAllParamsDateRangeXMLNew('pdbjewq', '2014-12-30',
                                                     '2014-12-31', '*')

pythonObject = SOAPpy.Types.simplify(responsedata)

dataArray = pythonObject["returnData"]["data"]
print dataArray
""" code to import data from file to mongodb

with open('ElkhornSlough,CA_SouthMarch_20141230_20141231.json') as data_file:
    data = json.load(data_file)
client = MongoClient()  # setting connection with the mongoclient
Ejemplo n.º 6
0
def getAllStationInformation():
    obj = RegionData()
    data = obj.getAllStationInfo()
    return jsonify({"stations": json.loads(dumps(data))})
Ejemplo n.º 7
0
def getRegionInformation():
    obj = RegionData()
    data = obj.getAllRegionInfo()
    return jsonify(result=dumps(data))
    'Great Bay, NH'
}, {
    'Stations': [{
        'Lat': 43.320089,
        'StationCode': 'welinwq',
        'Lon': -70.563442,
        'StationName': 'Inlet'
    }, {
        'Lat': 43.344711,
        'StationCode': 'welsmwq',
        'Lon': -70.549217,
        'StationName': 'Skinner Mill'
    }, {
        'Lat': 43.298347,
        'StationCode': 'welhtwq',
        'Lon': -70.587094,
        'StationName': 'Head of Tide'
    }, {
        'Lat': 43.340153,
        'StationCode': 'wellmwq',
        'Lon': -70.540603,
        'StationName': 'Little River Mout'
    }],
    'RegionId':
    28,
    'RegionName':
    'Wells, ME'
}]

obj = RegionData()
obj.insertRegionInfoIntoDB(regions)