kuon.watcher.adapters.bitskins.parser.sold_history   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 46.67%

Importance

Changes 0
Metric Value
wmc 3
eloc 19
dl 0
loc 33
ccs 7
cts 15
cp 0.4667
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A SoldHistoryParser.parse() 0 20 3
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3 1
import json
4
5 1
from kuon.api_response import APIResponse
6 1
from kuon.watcher.adapters.models.sold_history import SoldHistory
7 1
from kuon.watcher.adapters.models.sold_item import SoldItem
8
9
10 1
class SoldHistoryParser(object):
11
    """Parser class to parse the response of the sold history to the unified format"""
12
13 1
    @staticmethod
14 1
    def parse(results: dict) -> APIResponse:
15
        """Parse the sold history model
16
17
        :type results: dict
18
        :return:
19
        """
20
        response = SoldHistory(success=results['status'] == 'success')
21
        for item in results['data']['sales']:
22
            wear = item['wear_value']
23
            if wear is None:
24
                wear = -1.0
25
26
            sold_item = SoldItem(
27
                price=int(float(item['price']) * 100),
28
                wear_value=float(wear),
29
                sold_at=int(item['sold_at'])
30
            )
31
            response.add_sale(sold_item)
32
        return APIResponse(json.dumps(response.__dict__))
33