Ejemplo n.º 1
0
def display_data(value):
    """Displaying the head for the selected file."""
    db_value = db.get("file")
    if value is None and db_value is None:
        return ""
    elif value is None and not db_value is None:
        value = db_value
    format = FileUtils.file_format(value)
    if format == 'csv' or format == 'txt':
        path = FileUtils.path('raw', value)
        head = DataUtils.read_text_head(path)
        table_col = [
            html.Col(style={'width': "10%"}),
            html.Col(style={'width': "90%"})
        ]
        table_header = [
            html.Thead(html.Tr([html.Th("Row No"),
                                html.Th("Data")]))
        ]
        rows = []
        for i in range(len(head)):
            row = html.Tr([html.Td(i + 1), html.Td(head[i])])
            rows.append(row)
        table_body = [html.Tbody(rows)]
        table = dbc.Table(table_col + table_header + table_body,
                          bordered=True,
                          style=common.table_style)
        div = [
            common.msg("Selected File: " + value),
            common.msg("Selected Format: " + format), table,
            html.Br(), csv_properties_div
        ]
    elif format == 'xls' or format == 'xlsx':
        path = FileUtils.path('raw', value)
        xls = pd.ExcelFile(path)
        sheets = xls.sheet_names
        div = [
            common.msg("Selected File: " + value),
            common.msg("Selected Format: " + format),
            common.msg("Select Sheet:"),
            html.Div([
                dcc.Dropdown(id='xls-file-sheet',
                             options=[{
                                 'label': sheet,
                                 'value': sheet
                             } for sheet in sheets],
                             value=None,
                             multi=False)
            ],
                     style={
                         'margin': '10px',
                         'width': '50%'
                     }),
            html.Div([], id="display-xls-file")
        ]
    else:
        div = "Format Not Supported!!"
    db.put("file", value)
    db.put("format", format)
    return div
Ejemplo n.º 2
0
 def read_text_head(path: str):
     format = FileUtils.file_format(path)
     op = None
     if format == 'csv' or format == 'txt':
         with open(path) as myfile:
             head = [next(myfile).strip() for x in range(N)]
         op = head
     return op
Ejemplo n.º 3
0
 def read(dir: str, filename: str):
     format = FileUtils.file_format(filename)
     path = FileUtils.path(dir, filename)
     op = None
     if format == 'csv' or format == 'txt':
         with open(path) as myfile:
             head = [next(myfile).strip() for x in range(N)]
         op = head
     elif format == 'jpeg' or format == 'jpg' or format == 'gif':
         ""
     else:
         op = "Format Not Supported!!"
     return op