def create(self, **kwargs): area = kwargs['area'] features = Gewerbeanteile.features().filter(id_teilflaeche=area.id) df = features.to_pandas() basedata = ProjectManager().basedata df_branchen = basedata.get_table('Gewerbe_Branchen', 'Definition_Projekt').to_pandas() colors = plt.cm.Accent(np.linspace(0, 1, len(df))) idx = df['anteil_branche'] > 0 df = df[idx] colors = colors[idx] df_branchen.rename(columns={'ID_Branche_ProjektCheck': 'id_branche'}, inplace=True) joined = df.merge(df_branchen, on='id_branche') figure = plt.figure() subplot = figure.add_subplot(111) ax = joined['anteil_branche'].plot( kind='pie', labels=[''] * len(df), autopct='%.0f%%', figsize=(8, 8), title=' ', #shadow=True, #explode=[0.1] * len(table_df), colors=colors, ax=subplot) #title = ax.set_title(self.title) #title.set_position((.5, 1.0)) plt.figtext(.5, .92, self.title, horizontalalignment='center', fontsize=12) #, fontweight='bold') ax.set_ylabel('') ax.set_xlabel('') ax.legend(joined['Name_Branche_ProjektCheck'], loc='upper center', bbox_to_anchor=(0.5, 0.05)) # didn't find a way to pass custom colors directly for color, handle in zip(colors, ax.get_legend().legendHandles): handle.set_linewidth(2.0) handle.set_color(color) box = ax.get_position() ax.set_position([box.x0, box.y0 + box.y0 * 0.5, box.width, box.height]) figure.tight_layout() figure.subplots_adjust(bottom=0.2) return figure
def next_working_day(min_days_infront=2): ''' get the next working day in germany (no holidays, no saturdays, no sundays in all federal states) requires the basetable "Feriendichte" to hold days infront of today Parameters ---------- min_days_infront : int (default: 2) returned day will be at least n days infront Returns ------- datetime.date the next day without holidays, if day is out of range of basetable: today + min_days_infront ''' today = np.datetime64(date.today()) basedata = ProjectManager().basedata day = today + np.timedelta64(min_days_infront,'D') # get working days (excl. holidays) where = ("Wochentag <> 'Samstag' and " "Wochentag <> 'Sonntag' and " "Anteil_Ferien_Bevoelkerung = 0") table = basedata.get_table('Feriendichte', 'Basisdaten_deutschland') table.where = where df_density = table.to_pandas() # can't compare directly because datetime64 has no length dates = pd.to_datetime(df_density['Datum'], format='%Y/%m/%d %H:%M:%S.%f') df_density['Datum'] = dates.dt.tz_convert(None) df_density.sort_values('Datum', inplace=True) infront = np.where(df_density['Datum'] >= day)[0] if len(infront) > 0: # get the first day matching all conditions day = df_density.iloc[infront[0]]['Datum'] return pd.Timestamp(day).date()