Пример #1
0
    def test_load_table_with_columns(self):
        data = xls.load_table(os.path.join(os.path.dirname(__file__),
                                           'fixtures/xls_table_simple.xls'),
                              sheet_index=3,
                              columns=['col1', 'col2', 'col3', 'col4', 'col5'])

        self.assertEqual(data, [{
            'col1': 3.0,
            'col2': 'd',
            'col3': 3.0,
            'col4': 4.0,
            'col5': ''
        }, {
            'col1': '',
            'col2': 2.0,
            'col3': 3.0,
            'col4': 4.0,
            'col5': 'df'
        }, {
            'col1': '',
            'col2': 6.0,
            'col3': 7.0,
            'col4': 8.0,
            'col5': ''
        }, {
            'col1': 123.0,
            'col2': 23.0,
            'col3': 34.0,
            'col4': 45.0,
            'col5': 'qw'
        }])
Пример #2
0
 def test_load_table_simple(self):
     data = xls.load_table(os.path.join(os.path.dirname(__file__),
                                        'fixtures/xls_table_simple.xls'),
                           sheet_index=0)
     self.assertEqual(
         data,
         [[3.0, 'd', 3.0, 4.0, '', ''], ['', 2.0, 3.0, 4.0, 'df', '+'],
          ['', 6.0, 7.0, 8.0, '', ''], [123.0, 23.0, 34.0, 45.0, 'qw', '']])
Пример #3
0
    def test_load_table_with_columns(self):
        data = xls.load_table(os.path.join(os.path.dirname(__file__), 'fixtures/xls_table_simple.xls'), sheet_index=3,
                              columns=['col1', 'col2', 'col3', 'col4', 'col5'])

        self.assertEqual(data, [ {'col1': 3.0,   'col2': 'd', 'col3': 3.0,  'col4': 4.0,  'col5': ''},
                                 {'col1': '',    'col2': 2.0,  'col3': 3.0,  'col4': 4.0,  'col5': 'df'},
                                 {'col1': '',    'col2': 6.0,  'col3': 7.0,  'col4': 8.0,  'col5': ''},
                                 {'col1': 123.0, 'col2': 23.0, 'col3': 34.0, 'col4': 45.0, 'col5': 'qw'}])
Пример #4
0
 def test_load_table_with_rows(self):
     data = xls.load_table(os.path.join(os.path.dirname(__file__), 'fixtures/xls_table_simple.xls'), sheet_index=1,
                           rows=['row1', 'row2', 'row3', 'row4'])
     self.assertEqual(data,
                      {'row1': [3.0,   'd', 3.0,  4.0,  '',    ''],
                       'row2': ['',    2.0,  3.0,  4.0,  'df', '+'],
                       'row3': ['',    6.0,  7.0,  8.0,  '',    ''],
                       'row4': [123.0, 23.0, 34.0, 45.0, 'qw', '']})
Пример #5
0
    def test_load_table_with_rows_and_columns(self):
        data = xls.load_table(os.path.join(os.path.dirname(__file__), 'fixtures/xls_table_simple.xls'), sheet_index=6,
                              rows=[u'row1', u'row2', u'row3', u'row4'],
                              columns=['col1', 'col2', 'col3', 'col4', 'col5'])

        self.assertEqual(data, { 'row1': {'col1': 3.0,   'col2': u'd', 'col3': 3.0,  'col4': 4.0,  'col5': ''},
                                 'row2': {'col1': '',    'col2': 2.0,  'col3': 3.0,  'col4': 4.0,  'col5': u'df'},
                                 'row3': {'col1': '',    'col2': 6.0,  'col3': 7.0,  'col4': 8.0,  'col5': ''},
                                 'row4': {'col1': 123.0, 'col2': 23.0, 'col3': 34.0, 'col4': 45.0, 'col5': u'qw'} })
Пример #6
0
 def test_load_table_with_rows(self):
     data = xls.load_table(os.path.join(os.path.dirname(__file__),
                                        'fixtures/xls_table_simple.xls'),
                           sheet_index=1,
                           rows=['row1', 'row2', 'row3', 'row4'])
     self.assertEqual(
         data, {
             'row1': [3.0, 'd', 3.0, 4.0, '', ''],
             'row2': ['', 2.0, 3.0, 4.0, 'df', '+'],
             'row3': ['', 6.0, 7.0, 8.0, '', ''],
             'row4': [123.0, 23.0, 34.0, 45.0, 'qw', '']
         })
Пример #7
0
    def test_load_table_with_rows_and_columns(self):
        data = xls.load_table(os.path.join(os.path.dirname(__file__),
                                           'fixtures/xls_table_simple.xls'),
                              sheet_index=6,
                              rows=[u'row1', u'row2', u'row3', u'row4'],
                              columns=['col1', 'col2', 'col3', 'col4', 'col5'])

        self.assertEqual(
            data, {
                'row1': {
                    'col1': 3.0,
                    'col2': u'd',
                    'col3': 3.0,
                    'col4': 4.0,
                    'col5': ''
                },
                'row2': {
                    'col1': '',
                    'col2': 2.0,
                    'col3': 3.0,
                    'col4': 4.0,
                    'col5': u'df'
                },
                'row3': {
                    'col1': '',
                    'col2': 6.0,
                    'col3': 7.0,
                    'col4': 8.0,
                    'col5': ''
                },
                'row4': {
                    'col1': 123.0,
                    'col2': 23.0,
                    'col3': 34.0,
                    'col4': 45.0,
                    'col5': u'qw'
                }
            })
Пример #8
0
from the_tale.common.utils import xls

from the_tale.game.map.conf import map_settings
from the_tale.game.map.relations import TERRAIN

_xls_attributes = {
    'filename': map_settings.TERRAIN_PRIORITIES_FIXTURE,
    'rows': [terrain.name for terrain in TERRAIN.records]
}

_modify_row_names = lambda d: dict(
    (TERRAIN.index_name[key], value) for key, value in d.items())

_HEIGHT_POINTS = _modify_row_names(
    xls.load_table(sheet_index=0,
                   columns=[round(val / 10.0, 1) for val in xrange(-10, 11)],
                   **_xls_attributes))
_TEMPERATURE_POINTS = _modify_row_names(
    xls.load_table(sheet_index=1,
                   columns=[round(val / 10.0, 1) for val in xrange(0, 11)],
                   **_xls_attributes))
_WETNESS_POINTS = _modify_row_names(
    xls.load_table(sheet_index=2,
                   columns=[round(val / 10.0, 1) for val in xrange(0, 11)],
                   **_xls_attributes))
_VEGETATION_POINTS = _modify_row_names(
    xls.load_table(sheet_index=3,
                   columns=['DESERT', 'GRASS', 'FOREST'],
                   **_xls_attributes))
_SOIL_POINTS = _modify_row_names(
    xls.load_table(sheet_index=4,
Пример #9
0
import math

from deworld.layers import VEGETATION_TYPE

from the_tale.common.utils import xls

from the_tale.game.map.conf import map_settings
from the_tale.game.map.relations import TERRAIN


_xls_attributes = {'filename': map_settings.TERRAIN_PRIORITIES_FIXTURE,
                   'rows': [terrain.name for terrain in TERRAIN.records] }

_modify_row_names = lambda d: dict((getattr(TERRAIN, key), value) for key, value in list(d.items()))

_HEIGHT_POINTS = _modify_row_names(xls.load_table(sheet_index=0, columns=[ round(val/10.0, 1) for val in range(-10, 11)], **_xls_attributes))
_TEMPERATURE_POINTS = _modify_row_names(xls.load_table(sheet_index=1, columns=[ round(val/10.0, 1) for val in range(0, 11)], **_xls_attributes))
_WETNESS_POINTS = _modify_row_names(xls.load_table(sheet_index=2, columns=[ round(val/10.0, 1) for val in range(0, 11)], **_xls_attributes))
_VEGETATION_POINTS = _modify_row_names(xls.load_table(sheet_index=3, columns=['DESERT', 'GRASS', 'FOREST'], **_xls_attributes))
_SOIL_POINTS = _modify_row_names(xls.load_table(sheet_index=4, columns=[ round(val/10.0, 1) for val in range(0, 11)], **_xls_attributes))

def mid(left, right, x, left_value, right_value):
    if left == right: return left_value
    # return ( (x - left) * left_value + (right - x) * right_value) / (right - left)

    return (right_value - left_value) * (x - left) / (right - left) + left_value

class Biom(object):

    def __init__(self, id_):
        self.id = id_
Пример #10
0
 def test_load_table_simple(self):
     data = xls.load_table(os.path.join(os.path.dirname(__file__), 'fixtures/xls_table_simple.xls'), sheet_index=0)
     self.assertEqual(data, [ [3.0,   'd', 3.0,  4.0,  '',    ''],
                              ['',    2.0,  3.0,  4.0,  'df', '+'],
                              ['',    6.0,  7.0,  8.0,  '',    ''],
                              [123.0, 23.0, 34.0, 45.0, 'qw', '']])