示例#1
0
def delete(id):
    result = True
    example = Example()
    example.id = id
    example.deleted_at = datetime.datetime.now()
    # 根据id删除数据
    result = example.delete() > 0
    return jsonify(result)
    def test_reduce_interval(self):
        example = Example(self.minimum_data)
        example.reduce_interval(720)
        eq_(1415790000, example.period)
        eq_(datetime.datetime(2014, 11, 12, 12, 0), example.period_dt)
        eq_(720, example.interval)

        example.reduce_interval(1440)
        eq_(1415746800, example.period)
        eq_(datetime.datetime(2014, 11, 12, 0, 0), example.period_dt)
        eq_(1440, example.interval)
示例#3
0
 def test_add(self):
     data = self.minimum_data
     data.update(self.additional_data)
     example = Example(data)
     example2 = Example(data)
     example3 = example + example2
     eq_(2, example3.param1)
     eq_(4.6, example3.param2)
     eq_(2e-200, example3.param3)
     eq_(['1', '2', '3'], example3.param4)
     eq_({'1': 'val1', '2': 'val2'}, example3.param5)
示例#4
0
 def test_create_complete(self):
     example = Example(self.minimum_data)
     example.add_custom_data(self.additional_data)
     eq_(15, example.interval)
     eq_('alias/project', example.project)
     eq_('8.8.8.8', example.ip_address)
     eq_(1415823240, example.period)
     eq_(1, example.param1)
     eq_(2.3, example.param2)
     eq_(1e-200, example.param3)
     eq_(['1', '2', '3'], example.param4)
     eq_({'1': 'val1', '2': 'val2'}, example.param5)
 def test_create_complete(self):
     example = Example(self.minimum_data)
     example.add_custom_data(self.additional_data)
     eq_(15, example.interval)
     eq_('alias/project', example.project)
     eq_('8.8.8.8', example.ip_address)
     eq_(1415823240, example.period)
     eq_(1, example.param1)
     eq_(2.3, example.param2)
     eq_(1e-200, example.param3)
     eq_(['1', '2', '3'], example.param4)
     eq_({'1': 'val1', '2':'val2'}, example.param5)
示例#6
0
 def get(self, example_id):
     example = Example.get_by_id(int(example_id))
     if example is None:
         self.error(404)
     else:
         self.respond(example.value,
                      content_type='text/plain',
                      cache_life=60 * 60)
示例#7
0
def save():
    data = request.get_json()
    if data is not None and len(data) > 0:
        example = Example()
        example.set_attrs(data)
        example.created_at = datetime.datetime.now()
        example.updated_at = datetime.datetime.now()
        # 保存数据
        example.save()
        return jsonify(example.id)
    else:
        return jsonify(error="not found any data to save"), 400
示例#8
0
def update(id):
    result = True
    data = request.get_json()
    example = Example()
    example.set_attrs(data)
    example.id = id
    example.updated_at = datetime.datetime.now()
    # 根据id更新数据
    result = example.update() > 0
    return jsonify(result)
示例#9
0
    def test_reduce_interval(self):
        example = Example(self.minimum_data)
        example.reduce_interval(720)
        eq_(1415790000, example.period)
        eq_(datetime.datetime(2014, 11, 12, 12, 0), example.period_dt)
        eq_(720, example.interval)

        example.reduce_interval(1440)
        eq_(1415746800, example.period)
        eq_(datetime.datetime(2014, 11, 12, 0, 0), example.period_dt)
        eq_(1440, example.interval)
示例#10
0
    def execute(self, *args, **kwargs):
        datafile = self._get_file()
        header = None
        dt_epoch = datetime(1970, 1, 1)
        common_data = {}

        for line in datafile:

            try:
                line = line.decode('utf-8')

                if header is None:
                    header = line.strip().split('\t')
                    continue

                raw_data = line.strip().split('\t')
                ip_address = '.'.join(raw_data[0:4])
                raw_data = [self._fix_type(value) for value in raw_data]
                data = dict(zip(header[4:], raw_data[4:]))
                grouptime = datetime.strptime(str(data['grouptime']),
                                              '%Y%m%d%H%M')
                grouptime_interval = grouptime - dt_epoch
                common_data = {
                    'ip_address': ip_address,
                    'interval': self.interval,
                    'project': self.project.full_name,
                    'period': int(grouptime_interval.total_seconds()),
                }
                common_data.update(data)
                example = Example(common_data)
                self.process_example(example)

            except Exception as e:
                self.logger.info(str(e))
                if 'ip_address' in common_data:
                    self.logger.info('unknown error with example {0}'.format(
                        common_data['ip_address']))

        self.logger.info('Chunk {0} processed'.format(self.file))

        # clean
        datafile.close()
        os.remove(self.file)
示例#11
0
 def post(self):
     example = Example(value=self.params['value'])
     example.put()
     self.respond(example)
 def test_reduce_interval_fail(self):
     example = Example(self.minimum_data)
     with assert_raises(ValueError):
         example.reduce_interval(1500)
示例#13
0
 def test_create_minimum_data(self):
     example = Example(self.minimum_data)
     eq_(15, example.interval)
     eq_('alias/project', example.project)
     eq_('8.8.8.8', example.ip_address)
     eq_(1415823240, example.period)
 def test_validate_complete_data(self):
     example = Example(self.minimum_data)
     example.add_custom_data(self.additional_data)
     example.validate()
示例#15
0
 def test_tablename(self):
     eq_('example', Example.__tablename__)
     example = Example(self.minimum_data)
     eq_('example', example.__tablename__)
	def get(self, example_id):
		example = Example.get_by_id( int(example_id) )
		if example is None:
			self.error(404)
		else:
			self.respond(example.value, content_type='text/plain', cache_life=60*60)
示例#17
0
 def test_reduce_interval_fail(self):
     example = Example(self.minimum_data)
     with assert_raises(ValueError):
         example.reduce_interval(1500)
示例#18
0
 def test_validate_complete_data(self):
     example = Example(self.minimum_data)
     example.add_custom_data(self.additional_data)
     example.validate()
示例#19
0
 def test_validate_minimum_data(self):
     example = Example(self.minimum_data)
     example.validate()
 def test_validate_minimum_data(self):
     example = Example(self.minimum_data)
     example.validate()
	def get(self, example_id):
		example = Example.get_by_id( int(example_id) )
		if example is None:
			self.error(404)
		else:
			self.respond(example, cache_life=60*60) # cache for 1 hour
示例#22
0
 def test_key(self):
     example = Example(self.minimum_data)
     eq_('alias/project-15-1415823240-8.8.8.8', example.__key__)
	def post(self):
		example = Example(value=self.params['value'])
		example.put()
		self.respond(example)
示例#24
0
 def get(self, example_id):
     example = Example.get_by_id(int(example_id))
     if example is None:
         self.error(404)
     else:
         self.respond(example, cache_life=60 * 60)  # cache for 1 hour