本文整理汇总了Python中geokey.contributions.models.Observation类的典型用法代码示例。如果您正苦于以下问题:Python Observation类的具体用法?Python Observation怎么用?Python Observation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Observation类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_validate_full_invalid
def test_validate_full_invalid(self):
creator = UserF()
location = LocationFactory()
category = CategoryFactory()
TextFieldFactory.create(**{
'key': 'text',
'category': category,
'order': 0
})
NumericFieldFactory.create(**{
'key': 'number',
'category': category,
'order': 1
})
data = {'text': 'Text', 'number': 12}
observation = Observation.create(
properties=data, creator=creator, location=location,
category=category, project=category.project, status='active'
)
updater = UserF()
update = {'text': 'Udpated Text', 'number': 'abc', 'version': 1}
Observation.validate_full(category=category, data=update)
observation.update(properties=update, updator=updater)
self.assertEqual(observation.properties, data)
self.assertEqual(observation.version, 1)
示例2: create_new_observation
def create_new_observation(si_pull, geo_tweet, tweet_category, text_field, tweet_id_field):
"""Create new observation based on the tweet.
Parameters
-----------
si_pull: SocialInteractionPull
geo_tweet: array of tweets
tweet_category: Category Object
text_field: TextField Object
tweet_id_field: TweetID Object
"""
point = geo_tweet['geometry']
properties = {
text_field.key: geo_tweet['text'],
tweet_id_field.key: geo_tweet['id']
}
location = Location(
geometry=point,
creator=si_pull.socialaccount.user)
Observation.create(
properties=properties,
location=location,
project=si_pull.project,
creator=si_pull.socialaccount.user,
category=tweet_category,
status='active')
si_pull.updated_at = timezone.now()
si_pull.save()
示例3: test_validate_full_invalid_nubmer
def test_validate_full_invalid_nubmer(self):
category = CategoryFactory()
TextFieldFactory(**{
'key': 'text',
'category': category,
'order': 0
})
NumericFieldFactory(**{
'key': 'number',
'category': category,
'order': 1
})
data = {'text': 'Text', 'number': 'abc'}
Observation.validate_full(data=data, category=category)
示例4: test_validate_full_with_empty_number
def test_validate_full_with_empty_number(self):
category = CategoryFactory()
TextFieldFactory(**{
'key': 'text',
'category': category,
'order': 0
})
NumericFieldFactory(**{
'key': 'number',
'required': True,
'category': category,
'order': 1
})
data = {'text': 'bla'}
Observation.validate_full(data=data, category=category)
示例5: test_update_draft_observation
def test_update_draft_observation(self):
creator = UserF()
location = LocationFactory()
category = CategoryFactory()
TextFieldFactory.create(**{
'key': 'text',
'category': category,
'required': True,
'order': 0
})
NumericFieldFactory.create(**{
'key': 'number',
'category': category,
'order': 1
})
data = {'number': 12}
observation = Observation.create(
properties=data, creator=creator, location=location,
category=category, project=category.project,
status='draft'
)
updater = UserF()
update = {'number': 13}
observation.update(properties=update, updator=updater, status='draft')
self.assertEqual(observation.properties.get('number'), 13)
self.assertEqual(observation.version, 1)
示例6: test_validate_full_inactive_field
def test_validate_full_inactive_field(self):
category = CategoryFactory()
TextFieldFactory(**{
'key': 'text',
'category': category,
'order': 2
})
TextFieldFactory(**{
'key': 'inactive_text',
'category': category,
'status': 'inactive',
'required': True,
'order': 0
})
NumericFieldFactory(**{
'key': 'number',
'category': category,
'order': 1
})
data = {'text': 'Text', 'number': 12}
Observation.validate_full(category=category, data=data)
示例7: test_validate_full_with_inactive_field
def test_validate_full_with_inactive_field(self):
category = CategoryFactory()
TextFieldFactory(**{
'key': 'text',
'category': category,
'order': 0
})
TextFieldFactory(**{
'key': 'inactive_text',
'category': category,
'status': 'inactive',
'required': True,
'order': 1
})
NumericFieldFactory(**{
'key': 'number',
'category': category,
'order': 2
})
observation = ObservationFactory.create(**{
'properties': {'text': 'Text', 'number': 12},
'category': category,
'project': category.project
})
updater = UserF()
update = {'text': 'Udpated Text', 'number': 13}
Observation.validate_full(category=category, data=update)
observation.update(properties=update, updator=updater)
self.assertEqual(
observation.properties,
{'text': 'Udpated Text', 'number': 13}
)
self.assertEqual(observation.version, 2)
示例8: test_create_observation
def test_create_observation(self):
creator = UserF()
location = LocationFactory()
category = CategoryFactory()
TextFieldFactory(**{
'key': 'text',
'category': category,
'order': 0
})
NumericFieldFactory(**{
'key': 'number',
'category': category,
'order': 1
})
data = {'text': 'Text', 'number': 12}
observation = Observation.create(
properties=data, creator=creator, location=location,
category=category, project=category.project, status='active'
)
self.assertEqual(observation.properties, data)
示例9: post
def post(self, request, project_id):
name = self.request.POST.get('checklistName')
description = self.request.POST.get('checklistDescription')
creator = self.request.user
project = None
checklist_settings = None
#not the most robust method; need to rework...
if int(project_id) == 999999:
project = Project.create("MyChecklist", "", True, False, 'auth', creator) #can be true, auth, or false
checklist_settings = ChecklistSettings.objects.create(
project=project,
reminderson=True,
frequencyonexpiration='twice',
#frequencybeforeexpiration='one_week'
)
else:
project = Project.objects.get_single(self.request.user, project_id)
checklist_settings = ChecklistSettings.objects.get(project=project)
default_status = 'active' #can be 'active' or 'pending'
category = Category.objects.create(
project=project,
creator=creator,
name=name,
description=description,
default_status=default_status
)
latitude = self.request.POST.get('checklistLat')
longitude = self.request.POST.get('checklistLng')
geom_point = Point((float(longitude), float(latitude)))
geometry = GEOSGeometry(geom_point)
created_at = datetime.datetime.now()
location_status = 'active' #can be 'active' or 'pending'
location = Location.objects.create(
name=name,
description=description,
geometry=geometry,
created_at=created_at,
creator=creator,
private_for_project=project,
status=location_status
)
data = {} #e.g. {'text': 'Text', 'number': 12}
observation_status = 'active' #can be 'active' or 'pending'
observation = Observation.create(
properties=data,
creator=creator,
location=location,
project=project,
category=category,
status=observation_status
)
checklisttype = self.request.POST.get('checklistType')
numberofpeople = self.request.POST.get('checklistNumPeople')
numberofchildren = self.request.POST.get('checklistNumChildren')
numberoftoddlers = self.request.POST.get('checklistNumToddlers')
numberofinfants = self.request.POST.get('checklistNumInfants')
numberofpets = self.request.POST.get('checklistNumPets')
checklist = Checklist.objects.create(
name=name,
description=description,
project=project,
category=category,
creator=creator,
checklisttype=checklisttype,
numberofpeople=numberofpeople,
numberofchildren=numberofchildren,
numberoftoddlers=numberoftoddlers,
numberofinfants=numberofinfants,
numberofpets=numberofpets,
latitude=latitude,
longitude=longitude
)
default_items = DEFAULT_ITEMS
for item_dict in default_items:
dict_checklisttype = ""
dict_name = ""
dict_checklistitemdescription = ""
dict_checklistitemurl = ""
dict_checklistitemtype = ""
dict_quantityfactor = ""
dict_pertype = ""
dict_quantityunit = ""
dict_expiryfactor = ""
for key in item_dict:
if key == "checklisttype":
dict_checklisttype = item_dict[key]
elif key == "name":
#.........这里部分代码省略.........