简体   繁体   English

搜索最佳数据存储类型PYTHON

[英]Searching for an optimal data storage type PYTHON

i have following problem i am solving that reguires me to store lots of parameters and i would for general purposes consider it a calendar application. 我有以下问题,我正在解决这一问题,要求我存储许多参数,出于一般目的,我将其视为日历应用程序。 I am solving the problem in PYTHON since its the only limited ability i have. 我正在解决PYTHON中的问题,因为它只有我有限的能力。 I am learning the language, im by far NOT an expert or a skilled user of it yet. 我正在学习该语言,到目前为止,它还不是专家或熟练的用户。

I have a class that is a mainstay of my calendar. 我上课是我日历的中流tay柱。

class DayOfLife(object): 

def __init__(self, date, index, stary, mlady, muze_slouzit_mladeho = [], muze_slouzit_stareho = []):

        self.date = date
        self.index = index
        self.muze_slouzit_mladeho = muze_slouzit_mladeho
        self.muze_slouzit_stareho = muze_slouzit_stareho
        self.stary = stary
        self.mlady = mlady

muze_slouzit_mladeho and _stareho is a list of possible people who can be used for work. muze_slouzit_mladeho_stareho是可用于工作的可能人员的列表。

Index is parameter describing how "bothersome" a day can be. 索引是描述一天可以有多“令人讨厌”的参数。 Mondays are better then Sundays and saturdays etc. 周一比周日和周六等要好。

stary and mlady is a definitive choice of a selected persons for current day. starymlady是当前选定人的确定选择。 (those i expect my program to generate) (那些我希望我的程序生成的)

I create a list of days (DayOfLife object) and assign each a date in "2017-01-01" format. 我创建一个天列表 (DayOfLife对象),并以“ 2017-01-01”格式为每个日期分配一个日期。

I then populate the list of days to have all the values i need except stary and mlady (those i expect my program to generate) 然后,我填充天列表,以获取除stary和mlady(我希望程序生成的那些值)之外的所有我需要的值

NOW the ISSUE . 现在的问题 I am not sure if my approach is the "good" one if i want to perform stuff like : 如果我要执行以下操作,我不确定我的方法是否是“好”方法:

1: sort the list by total amount of available people for each day (number of keys in muze_slouzit_mladeho , since i would love to populate those hardest days first. At the same time i need to access easily and quickly the day before and day after of those days. 1:按每天可用人员总数对列表进行排序( muze_slouzit_mladeho中 ,因为我希望首先填充最困难的日子。与此同时,我需要方便快捷地访问的前一天和后一天那些天。

So something like sort the list by number of keys in those list attributes ( muze_slouzit_mladeho )and then assign something from the possible keys and either remove or mark as used somehow the same keys in day before and after since on key can not be in two following days. 因此,类似按列表属性( muze_slouzit_mladeho )中的键数对列表进行排序,然后从可能的键中分配内容,然后在前后的某天将相同的键删除或标记为已使用因为on键不能在以下两个键中天。 (Persons cannot attend two days in a row). (人员不能连续两天参加)。 At the moment i feel that if i sort the list i would have to then iterate through the entire list to find the previous day by date and update its key values. 目前,我觉得如果我对列表进行排序,那么我将不得不遍历整个列表以按日期查找前一天并更新其键值。 It feels better to be able to just write something like 能够像这样写东西感觉更好

day[i-1] remove key
day[i+1] remove key

I am unsure how would i do that at all. 我不确定我该怎么做。 I have no idea how to use databases at the moment. 我现在不知道如何使用数据库。 I think my data type will have to evolve into something else, i might need to add another list to keep scores of people who i removed due to the "two days in a row rule" instead of removing it in the original. 我认为我的数据类型将不得不演变为其他类型,我可能需要添加另一个列表来保留由于“连续两天规则”而被删除的人员的得分,而不是将其从原始列表中删除。

I think i will think of something but i expect it to be terribly inefficient. 我想我会想到的东西,但我希望它效率极低。 So i would like to hear some opinion on how to approach that. 因此,我想听听一些有关如何解决该问题的意见。 Do i have to learn SQLite? 我必须学习SQLite吗? Will it help? 有帮助吗? Can i somehow make the array of DayOfLife objects indexable? 我可以以某种方式使DayOfLife对象数组可索引吗? Or can i access the objects by their attributes? 还是可以通过对象的属性访问对象? I am not sure if that would work. 我不确定这是否行得通。 I might really be dumb here. 我可能在这里真傻。

Create a dict with the date as key and values with your DayOfLife object and amount of available people , eg 创建一个日期为键的dict ,并使用DayOfLife objectamount of available people (例如)创建值

my_dict = {'Date':2017-01-01, 'DayOfLife':<DayOfLife object>, 'amount':10}

Sort my_diict using key = my_dict['amount'] to a list object . 排序my_diict使用key = my_dict['amount']到一个list object

Access Day before/after: 访问日的前/后:

 E.g. current object Date = 2017-01-01
 Day before = 2017-01-01 - 1 = 2016-12-31; my_dict[ 2016-12-31]
 Day after= 2017-01-01 + 1 = 2017-01-02; my_dict[ 2017-01-02]

You sure be want to save your Data permanently, so you have to decide How to? 您确定要永久保存数据,因此必须决定如何做? For now start with useing csv module . 现在开始使用csv module

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM