SoldHistoryParser.parse()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 7.608

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 20
ccs 2
cts 10
cp 0.2
rs 9.75
c 0
b 0
f 0
cc 3
nop 1
crap 7.608
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