示例#1
0
 def getSampleYears(self):
     dates = list(map(lambda x: (x.date), Sample.findAllSamples()))
     years = []
     for date in dates:
         if date.year not in years:
             years.append(date.year)
     years.sort(reverse=True)
     return years
示例#2
0
 def removeSample(self, id):
     sample = Sample.findSampleById(id)
     if sample:
         sample.delete()
         return {
             "message": "The sample with id '{}' is deleted!".format(id)
         }
     else:
         return "The sample does not exist!"
示例#3
0
    def addSample(self, id):
        data = SampleService.parser.parse_args()
        sample = Sample.findSampleById(id)

        if sample:
            return "Sample already exists!"
        else:
            sample = Sample(data["id"], data["date"], data["quality"],
                            data["x_coor"], data["y_coor"], data["date_added"],
                            data["location_id"], data["owner_id"],
                            data["taxon_values"])
            sample.save()
            return sample.json()
示例#4
0
    def updateSample(self, id):
        data = SampleService.parser.parse_args()
        sample = Sample.findSampleById(id)

        if sample:
            sample.date = data["date"]
            sample.quality = data["quality"]
            sample.x_coor = data["x_coor"]
            sample.y_coor = data["y_coor"]
            sample.date_added = data["date_added"]
            sample.location_id = data["location_id"]
            sample.owner_id = data["owner_id"]
            sample.taxon_values = data["taxon_values"]
        else:
            sample = Sample(data["id"], data["date"], data["quality"],
                            data["x_coor"], data["y_coor"], data["date_added"],
                            data["location_id"], data["owner_id"],
                            data["taxon_values"])

        sample.save()
        return sample.json()
示例#5
0
 def getAllSamplesByLocation(self, locationId):
     return list(
         map(lambda x: x.json(),
             Sample.findAllSamplesByLocationId(locationId)))
示例#6
0
 def getAllSamples(self):
     return list(map(lambda x: x.json(), Sample.findAllSamples()))
示例#7
0
 def getSample(self, id):
     sample = Sample.findSampleById(id)
     if sample:
         return sample.json(), 201
     return {"message": "The sample is not found!"}, 404
示例#8
0
 def getRecentSample(self, count):
     return list(
         map(lambda x: x.json(), Sample.findRecentSamples(self, count)))