def input_non_project_object(self, area): use_last_objects = self.config.get_area(area).get( "use_last_objects", False) last_objects = [] if use_last_objects: last_objects = self.db.get_last_objects( area, self.config.get_num_last_objects()) last_objects_dict = { "[{0}]".format(x): k[0] for x, k in enumerate(last_objects) } # Transform last objects into [x]: object tags if len(last_objects) > 0: p = Printer() last_objects_dict = { "[{0}]".format(x): k for x, k in enumerate(last_objects) } p.add("Last {0} {1} Objects :: ".format( len(last_objects), area)) p.newline() for k, v in sorted(last_objects_dict.items()): p.add("{0} {1}".format(k, v)) p.newline() p.print() object = prompt("Object :: ", completer=WordCompleter(last_objects), vi_mode=True) if use_last_objects: if object in last_objects_dict: return last_objects_dict[object] return object
def print_rendered_string(area_code, area, date_to_display, object_name, duration, purpose): p = Printer() e = get_rendered_string(area_code, area, date_to_display, object_name, duration, purpose) p.add(*e) p.print()
def __load_configuration(self, configuration_path): """ Load the configuration from the supplied path. If the file does not exist at this path, create it from the default config settings. """ expanded_path = path.expanduser(configuration_path) if not path.exists(path.dirname(expanded_path)): makedirs(path.dirname(expanded_path)) if not path.exists(expanded_path): self.__write_config_file(expanded_path, self.DEFAULT_CONFIG) p = Printer() p.add_header("Wilcume on Færeld") p.newline() p.add("This looks like it is your first time running Færeld.") p.newline() p.add("A config file has been created at ", Highlight(expanded_path), ".") p.newline() p.add( "This contains some default values to get you started, ", "but you should take a look to add your own areas and projects.", ) p.newline() p.add( "For more information, please see the configuration documentation ", "at https://faereld.readthedocs.io/en/latest/usage/configuration.html", ) p.newline() p.print() else: self.__load_configuration_values(expanded_path)
def print(self): self.simple_summary.print() p = Printer() p.newline() p.add_header("Total Time Logged Per Project") p.newline() graph = ( SummaryGraph(self.project_time_map) .set_max_width(utils.max_width(self.config.get_max_graph_width())) .set_key_transform_function(self.config.get_project_name) .sort_graph(reverse=True) .generate() ) for row in graph: p.add_nowrap(row) p.newline() p.add_header("Total Time Logged Per Area Per Project") p.newline() multigraph = ( SummaryMultiGraph(self.project_area_time_map, 30) .set_header_transform_function(self.config.get_project_name) .generate() ) for row in multigraph: p.add_nowrap(row) p.print()
def print(self): self.simple_summary.print() p = Printer() p.newline() p.add_header(f"Summary For {self.area_name}") p.newline() minimum = None maximum = None average = datetime.timedelta() for entry in self.area_time_map[self.area]: if minimum is None or minimum > entry: minimum = entry if maximum is None or maximum < entry: maximum = entry average += entry average = average / len(self.area_time_map[self.area]) p.add( f"The lowest recorded entry for {self.area_name} is ", f"{utils.format_time_delta(minimum)}.", ) p.add( f"The highest recorded entry for {self.area_name} is ", f"{utils.format_time_delta(maximum)}.", ) p.add( f"The average entry for {self.area_name} is ", f"{utils.format_time_delta(average)}.", ) p.newline() p.add_header(f"Entry Time Distribution for {self.area_name}") p.newline() box = (BoxPlot(self.area_time_map).set_max_width( utils.max_width(self.config.get_max_graph_width()) ).set_exclude_list( self.config.get_exclude_from_entry_time_distribution()).generate()) for row in box: p.add_nowrap(row) p.newline() p.add_header("LAST {0} ENTRIES".format(len(self.last_entries))) p.newline() for entry in self.last_entries: if self.config.get_use_wending(): start_date = entry.start.strftime("{daeg} {month} {gere}") else: start_date = entry.start.strftime("%d %b %Y") p.add(*utils.get_rendered_string( entry.area, self.config.get_area(entry.area), start_date, self.config.get_object_name(entry.area, entry.obj), utils.time_diff(entry.start, entry.end), entry.purpose, )) p.print()
def print(self): self.simple_summary.print() p = Printer() p.newline() p.add_header("Total Time Logged Per Area") p.newline() # Sum all the timedeltas for the summary graph summary_time_map = dict( map( lambda x: (x[0], sum(x[1], datetime.timedelta())), self.area_time_map.items(), ) ) graph = ( SummaryGraph(summary_time_map) .set_max_width(utils.max_width(self.config.max_graph_width)) .set_exclude_list(self.config.exclude_from_total_time) .generate() ) for row in graph: p.add_nowrap(row) p.newline() p.add_header("ENTRY TIME DISTRIBUTION PER AREA") p.newline() box = ( BoxPlot(self.area_time_map) .set_max_width(utils.max_width(self.config.max_graph_width)) .set_exclude_list(self.config.exclude_from_entry_time_distribution) .generate() ) for row in box: p.add_nowrap(row) p.newline() p.add_header("LAST {0} ENTRIES".format(len(self.last_entries))) p.newline() for entry in self.last_entries: if self.config.use_wending: start_date = entry.start.strftime("{daeg} {month} {gere}") else: start_date = entry.start.strftime("%d %b %Y") p.add( *utils.get_rendered_string( entry.area, self.config.get_area(entry.area), start_date, self.config.get_object_name(entry.area, entry.obj), utils.time_diff(entry.start, entry.end), entry.purpose, ) ) p.print()
def summary(self, target): summary = self.db.get_summary(target=target, detailed=True) if target is None: Printer().add_mode_header("Summary").print() else: if target not in self.config.get_areas(): p = Printer() p.add("ERROR: No area found for: [", Highlight(target), "]") p.newline() p.add("Valid areas are: ") for area in self.config.get_areas(): p.add(f"[{area}]") p.print() return Printer().add_mode_header(f"Summary [{target}]").print() summary.print()
def print(self): self.simple_summary.print() p = Printer() def day_num_to_string(day_num): dates = { 0: "MON", 1: "TUE", 2: "WED", 3: "THU", 4: "FRI", 5: "SAT", 6: "SUN", } return dates[day_num] def zero_pad_hour(hour): if len(str(hour)) == 1: return "0{}".format(str(hour)) return str(hour) p.newline() p.add_header("Total Time Logged Per Day") p.newline() graph = (SummaryGraph(self.day_delta_map).set_max_width( utils.max_width( self.config.max_graph_width)).set_key_transform_function( day_num_to_string).generate()) for row in graph: p.add_nowrap(row) p.newline() p.add_header("Total time logged per hour") p.newline() graph = (SummaryGraph(self.hour_delta_map).set_max_width( utils.max_width( self.config.max_graph_width)).set_key_transform_function( zero_pad_hour).generate()) for row in graph: p.add_nowrap(row) p.print()
def print(self): summary = "{0} DAYS // {1} ENTRIES // TOTAL {2}" p = Printer() p.add_header( summary.format(self.days, self.entries, self.formatted_time)) p.print()