HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonMinor

Day planner / logger

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
plannerdaylogger

Problem

This is a simple program I've made using Qt Creator and Pyside:

  • I made a list of activities that I would like to enforce



  • Then I made a program that randomly pick them based on chance



  • It has some buttons to set an activity as Completed/Postponed



  • It can be added new activities for extra 'points'



  • Some activities can take longer than a day, so they are Due to a certain day



  • And finally there's a log in day/week/month with scores and count for each activity



I'm looking for an analysis on my program structure and data flow (this is perhaps my second GUI program, so it probably has many flaws). But I would be very happy to learn how the program feels and what should be added/removed (features). But mostly I'm looking towards doing things properly.

To execute it you need to have these files in the folder:

  • Activities.py



  • day_planner.py



  • day_planner_ui.py



  • due_window_ui.py



Activities.py

```
import random

class Activity:
"""Set the basic activity properties"""
def __init__(self, name, occurrence, occur_time, postpone_cost, add_credit, options=None, completion_time=None):
self.name = name
self.occurrence = occurrence
self.occur_time = occur_time
self.postpone_cost = postpone_cost
self.add_credit = add_credit
self.options = options
self.completion_time = completion_time

def random_occur(self):
"""randomly chance of this activity occurring in the day"""
chance = 0
if self.occur_time == 'Week':
chance = self.occurrence / 7.0
elif self.occur_time == 'Month':
chance = self.occurrence / 30.0

rand = random.random()
if rand other.name

activities = {
"Learn Language": {
'options': ["French", "German"],
'occurrence': 1,
'occur_time': "Week",
'postpone_cost': 2,
'add_credit': 1
},
"Learn Programming": {
'options': ["Python", "C", "C#"],
'occurrence':

Solution


  • If you want enum types but can't upgrade to Python 3.4, consider using the backport of its standard library enum module.



-
The use of the class method and class attributes in TreeData seems to me a bit like two classes crammed into one. Consider moving the class level stuff to another class, maybe like this:

class TreeDatas(object):
    def __init__(self):
        self.day = TreeData("Day")
        self.week = TreeData("Week")
        self.month = TreeData("Month")

    def setup(self, main_window):
        ...


-
On Python 2 remember to make classes inherit from object. Otherwise you get an old-style class with some quirks.

  • The code relies on a global progress variable which is created under the if __name__ == "__main__": guard. The guard makes it possible to import the module into a larger app but the missing global variable would prevent it from working. You could make progress an attribute of MainFrame instead.

Code Snippets

class TreeDatas(object):
    def __init__(self):
        self.day = TreeData("Day")
        self.week = TreeData("Week")
        self.month = TreeData("Month")

    def setup(self, main_window):
        ...

Context

StackExchange Code Review Q#78302, answer score: 6

Revisions (0)

No revisions yet.