def lpi_pk(dimapath): """ returns a dataframe with tblplots, tbllines, tbllpiheader and tblLPIDetail joined. PrimaryKey field is made using formdate and plotkey """ lpi_header = arcno.MakeTableView('tblLPIHeader', dimapath) lpi_detail = arcno.MakeTableView('tblLPIDetail', dimapath) lines = arcno.MakeTableView('tblLines', dimapath) plots = arcno.MakeTableView('tblPlots', dimapath) # joins plot_line = pd.merge(plots, lines, how="inner", on="PlotKey") lpihead_detail = pd.merge(lpi_header, lpi_detail, how="inner", on="RecKey") plot_line_det = pd.merge(plot_line, lpihead_detail, how="inner", on="LineKey") arc = arcno() # # tmp1 = fix_fields(plot_line_det, 'DateModified').copy() # tmp2 = fix_fields(tmp1,'ElevationType').copy() plot_pk = arc.CalculateField(plot_line_det, "PrimaryKey", "PlotKey", "FormDate") return plot_pk
def qual_pk(dimapath): """ returns a dataframe with tblplots, tbllines, tblgapheader and tblgapDetail joined. PrimaryKey field is made using formdate and plotkey no dup fields """ arc = arcno() header = arcno.MakeTableView('tblQualHeader', dimapath) detail = arcno.MakeTableView('tblQualDetail', dimapath) # joins head_detail = pd.merge(header, detail, how="inner", on="RecKey") plot_pk = arc.CalculateField(head_detail, "PrimaryKey", "PlotKey", "FormDate") return plot_pk
def bsne_pk(dimapath): """ returns a dataframe with tblplots, tblBSNE_Box, tblBSNE_Stack and tblBSNE_BoxCollection and tblBSNE_TrapCollection joined. if tblBSNE_TrapCollection does not exist in networkdima, skip it and join: box, stack and boxcollection. if it exists, join trapcollection and stack. PrimaryKey field is made using formdate and plotkey """ ddt = arcno.MakeTableView("tblBSNE_TrapCollection", dimapath) arc = arcno() if ddt.shape[0] > 0: ddt = arcno.MakeTableView("tblBSNE_TrapCollection", dimapath) stack = arc.MakeTableView("tblBSNE_Stack", dimapath) # df = arc.AddJoin(stack, ddt, "StackID", "StackID") df = pd.merge(stack, ddt, how="inner", on="StackID") df2 = arc.CalculateField(df, "PrimaryKey", "PlotKey", "collectDate") df2tmp = fix_fields(df2, "Notes") df2tmp2 = fix_fields(df2tmp, "DateModified") df2tmp3 = fix_fields(df2tmp2, "DateEstablished") return df2tmp3 else: box = arcno.MakeTableView("tblBSNE_Box", dimapath) stack = arcno.MakeTableView("tblBSNE_Stack", dimapath) boxcol = arcno.MakeTableView('tblBSNE_BoxCollection', dimapath) # differences 1 # dfx = pd.merge(stack, box[cols_dif1], left_index=True, right_index=True, how="outer") df = pd.merge(box, stack, how="inner", on="StackID") df2 = pd.merge(df, boxcol, how="inner", on="BoxID") # fix df2 = arc.CalculateField(df2, "PrimaryKey", "PlotKey", "collectDate") df2tmp = fix_fields(df2, "Notes") df2tmp2 = fix_fields(df2tmp, "DateModified") df2tmp3 = fix_fields(df2tmp2, "DateEstablished") return df2tmp3
def gap_pk(dimapath): """ returns a dataframe with tblplots, tbllines, tblgapheader and tblgapDetail joined. PrimaryKey field is made using formdate and plotkey """ arc = arcno() gap_header = arcno.MakeTableView('tblGapHeader', dimapath) gap_detail = arcno.MakeTableView('tblGapDetail', dimapath) lines = arcno.MakeTableView('tblLines', dimapath) plots = arcno.MakeTableView('tblPlots', dimapath) # joins plot_line = pd.merge(plots,lines,how="inner", on="PlotKey") gaphead_detail = pd.merge(gap_header,gap_detail, how="inner", on="RecKey") plot_line_det = pd.merge(plot_line,gaphead_detail,how="inner", on="LineKey") # fixing dup fields # tmp1 = fix_fields(plot_line_det, 'DateModified') # tmp2 = fix_fields(tmp1, 'ElevationType') plot_pk = arc.CalculateField(plot_line_det, "PrimaryKey", "PlotKey", "FormDate") return plot_pk
def sperich_pk(dimapath): """ returns a dataframe with tblplots, tbllines, tblsperichheader and tblsperichDetail joined. PrimaryKey field is made using formdate and plotkey """ arc = arcno() spe_header = arcno.MakeTableView('tblSpecRichHeader', dimapath) spe_detail = arcno.MakeTableView('tblSpecRichDetail', dimapath) lines = arcno.MakeTableView('tblLines', dimapath) plots = arcno.MakeTableView('tblPlots', dimapath) # joins plot_line = pd.merge(plots, lines, how="inner", on="PlotKey") spehead_detail = pd.merge(spe_header, spe_detail, how="inner", on="RecKey") plot_line_det = pd.merge(plot_line, spehead_detail, how="inner", on="LineKey") # tmp1 = fix_fields(plot_line_det,"DateModified") # tmp2 = fix_fields(tmp1,"ElevationType") # tmp3 = fix_fields(tmp2, "SpeciesList") plot_pk = arc.CalculateField(plot_line_det, "PrimaryKey", "PlotKey", "FormDate") return plot_pk
def plantden_pk(dimapath): """ returns a dataframe with tblplots, tbllines, tblplantdenheader and tblplantdenDetail joined. PrimaryKey field is made using formdate and plotkey """ arc = arcno() pla_header = arcno.MakeTableView('tblPlantDenHeader', dimapath) pla_detail = arcno.MakeTableView('tblPlantDenDetail', dimapath) lines = arcno.MakeTableView('tblLines', dimapath) plots = arcno.MakeTableView('tblPlots', dimapath) # joins plot_line = pd.merge(plots, lines, how="inner", on='PlotKey') plahead_detail = pd.merge(pla_header, pla_detail, how="inner", on='RecKey') plot_line_det = pd.merge(plot_line, plahead_detail, how="inner", on='LineKey') plot_pk = arc.CalculateField(plot_line_det, "PrimaryKey", "PlotKey", "FormDate") return plot_pk
def no_pk(tablefam: str = None, dimapath: str = None, tablename: str = None): """ """ arc = arcno() fam = { 'plantprod': ['tblPlantProdDetail', 'tblPlantProdHeader'], 'soilstab': ['tblSoilStabDetail', 'tblSoilStabHeader'], 'soilpit': ['tblSoilPits', 'tblSoilPitHorizons'] } try: if tablefam is not None and ('plantprod' in tablefam): header = arcno.MakeTableView(fam['plantprod'][1], dimapath) detail = arcno.MakeTableView(fam['plantprod'][0], dimapath) head_det = pd.merge(header, detail, how="inner", on="RecKey") head_det = arc.CalculateField(head_det, "PrimaryKey", "PlotKey", "FormDate") return head_det elif tablefam is not None and ('soilstab' in tablefam): header = arcno.MakeTableView(fam['soilstab'][1], dimapath) detail = arcno.MakeTableView(fam['soilstab'][0], dimapath) head_det = pd.merge(header, detail, how="inner", on="RecKey") head_det = arc.CalculateField(head_det, "PrimaryKey", "PlotKey", "FormDate") return head_det elif tablefam is not None and ('soilpit' in tablefam): print("soilpit") pits = arcno.MakeTableView(fam['soilpit'][0], dimapath) horizons = arcno.MakeTableView(fam['soilpit'][1], dimapath) merge = pd.merge(pits, horizons, how="inner", on="SoilKey") allpks = lpi_pk(dimapath) iso = allpks.loc[:, [ "PrimaryKey", "EstablishDate", "FormDate", "DateModified" ]].copy() merge['FormDate2'] = pd.to_datetime( merge.DateRecorded.apply(lambda x: pd.Timestamp(x).date())) mergepk = date_column_chooser( merge, iso) if "tetonAIM" not in dimapath else pd.merge( merge, iso, how="left", left_on="FormDate2", right_on="FormDate").drop_duplicates('HorizonKey') if "DateModified2" in mergepk.columns: mergepk.drop([ 'EstablishDate', "FormDate", 'FormDate2', "DateModified2" ], axis=1, inplace=True) else: mergepk.drop(['EstablishDate', "FormDate", 'FormDate2'], axis=1, inplace=True) return mergepk else: no_pk_df = arcno.MakeTableView(tablename, dimapath) # print('netdima in path') if ('Network_DIMAs' in dimapath) and (tablefam == None): if ('tblPlots' in tablename) or ('tblLines' in tablename): print("lines,plots; networkdima in the path") fulldf = bsne_pk(dimapath) iso = arc.isolateFields(fulldf, 'PlotKey', 'PrimaryKey').copy() no_pk_df = pd.merge( no_pk_df, iso, how="inner", on=["PlotKey"]).drop_duplicates([ "LineKey", "PrimaryKey" ]) if "tblLines" in tablename else pd.merge( no_pk_df, iso, how="inner", on=["PlotKey"]).drop_duplicates(["PrimaryKey"]) return no_pk_df else: print("network, but not line or plot, no pk") if 'Sites' in tablename: no_pk_df = no_pk_df[(no_pk_df.SiteKey != '888888888') & (no_pk_df.SiteKey != '999999999')] return no_pk_df else: return no_pk_df elif ('Network_DIMAs' in dimapath) and ('fake' in tablefam): if ('tblPlots' in tablename) or ('tblLines' in tablename): fulldf = lpi_pk(dimapath) iso = arc.isolateFields(fulldf, 'PlotKey', 'PrimaryKey').copy() no_pk_df = pd.merge( no_pk_df, iso, how="inner", on=["PlotKey"]).drop_duplicates([ "LineKey", "PrimaryKey" ]) if "tblLines" in tablename else pd.merge( no_pk_df, iso, how="inner", on=["PlotKey"]).drop_duplicates(["PrimaryKey"]) return no_pk_df else: print("network, but not line or plot, no pk --fakebranch") if 'Sites' in tablename: no_pk_df = no_pk_df[(no_pk_df.SiteKey != '888888888') & (no_pk_df.SiteKey != '999999999')] return no_pk_df else: return no_pk_df else: if ('tblPlots' in tablename) or ('tblLines' in tablename): print('not network, no tablefam') fulldf = lpi_pk(dimapath) iso = arc.isolateFields(fulldf, 'PlotKey', 'PrimaryKey').copy() no_pk_df = pd.merge( no_pk_df, iso, how="inner", on=["PlotKey"]).drop_duplicates([ "LineKey", "PrimaryKey" ]) if "tblLines" in tablename else pd.merge( no_pk_df, iso, how="inner", on=["PlotKey"]).drop_duplicates(["PrimaryKey"]) return no_pk_df else: print("not network, not line or plot, no pk") if 'Sites' in tablename: no_pk_df = no_pk_df[(no_pk_df.SiteKey != '888888888') & (no_pk_df.SiteKey != '999999999')] return no_pk_df else: return no_pk_df # return no_pk_df except Exception as e: print(e)