Skip to content

CsvScriptModel

CSV Script Models are a type of model that executes a command with a given set of args. This command needs to return a well formatted with a header row to stdout.

Visivo will be able to access the generate file as a model by storing a sqlite file in the source directory.

Example

Echoing all of your data is probably not a very practical example, but it does nicely demonstrate how the feature works!

models:
  - name: csv
    table_name: csv
    args:
        - echo
        - |
          x,y
          1,9
          2,1
          3,2
          4,3
          5,5
          6,8

In this example we'll use python to generate a csv of processes running on your machine and make that csv available to Visivo as a model for analysis.

created_processes_csv.py
import subprocess
import csv
import sys

# Define the CSV file to write
csv_file = "data/processes.csv"

# Execute the 'ps aux' command
result = subprocess.run(["ps", "aux"], stdout=subprocess.PIPE, text=True)

# Split the output into lines
lines = result.stdout.strip().split("/n")

# Write CSV to stdout
writer = csv.writer(sys.stdout)
writer.writerow(
    ["USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND"]
)  # Header

for line in lines[1:]:  # Skip the header line from the ps output
    row = line.split(None, 10)  # Split on whitespace, but only for the first 10 columns
    writer.writerow(row)
With your script ready to go, all you have to do is convert python create_processes_csv.py into the args list format in a model.
models:
  - name: processes
    table_name: processes
    args:
      - python
      - create_processes_csv.py

One of the best use cases for this type of model is to store a static csv in your project and cat it into a model. This great because it's simple and allows you to version control your csv data.

file.csv
columns,go,up,here
1,text,more text,6
2,stuff,more stuff,7
Then just cat the csv file in a model.
models:
  - name: file_model
    table_name: file_model
    args:
      - cat
      - file.csv

The args are python subprocess list args and you can read their source documentation here.

Attributes

Field Type Default Description
path string None A unique path to this object
name string None The unique name of the object across the entire project.
table_name string model The name to give the resulting models table
args array None An array of the variables that build your command to run.