Skip to content

Commit

Permalink
add tutorial part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
shshemi committed Aug 3, 2024
1 parent 72875c3 commit e9fe8ad
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 5 deletions.
Binary file added tutorial/images/command_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorial/images/schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorial/images/sheet_view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 121 additions & 5 deletions tutorial/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,137 @@ In this tutorial, following CSV files are used as examples, which can be found i
3. **company.csv**: A set of companies with their properties generated by an LLM.
4. **employment.csv**: A relation table between user and company, showing when a user gets employed by a company.

It is recommended to take the time to look at each CSV file to get a grasp of what each one contains.

## Opening file(s)

To open a single file in Tabiew, simply use the following command:

```
```shell
tw <file_name>
```

For instance, to open the housing price dataset file, use the following command:

```shell
tw housing.csv
```

This command will load the `housing.csv` file and show the following screen:

![image not found](images/main_page.png)

The data from housing.csv in the main table, while the status bar at the bottom of the page provides table properties such as name and shape. Furthermore, the status bar also show index of the current tab.

## Command Mode

Command mode can be activated by pressing `:`, then typing the command and pressing the `enter` key. While in command mode, pressing the `esc` key cancels the command. The command is shown as you type in at the bottom of the screen in place of the status bar.

Replace `<file_name>` with the name of the tabular file you wish to view. This command will load the file and display its contents.

To open the housing price dataset file, use the following command:
## Table Navigation

Navigating through tables in Tabiew is intuitive and efficient with the following key mappings:

| Key Combination | Action |
|------------------------|-------------------------------|
| `k` or `Arrow Up` | Move up one row in the table |
| `j` or `Arrow Down` | Move down one row in the table|
| `Page Up` or `Ctrl+b` | Move one page up |
| `Page Down` or `Ctrl+f`| Move one page down |
| `Ctrl+u` | Move up half a page |
| `Ctrl+d` | Move down half a page |
| `Home` or `g` | Move to the first row |
| `End` or `G` | Move to the last row |

Use these key mappings to efficiently navigate through your data, switch views, and manage multiple open files with ease.

Alternatively, you can use the `:goto` command to jump to a specific row, or just start entering the number and the app will automatically enters the command for you.

## Sheet View

By default, all rows are shown in a single line in the table view. Furthermore, if the requred width to show table is larger than the screen, the columns are squeezed to fix the screen. Therefore, To enhance readability, you can switch to the **sheet view** by pressing the `v` key. The sheet view allows you to visit each row individually and scroll horizontally if it doesn't fit into a page.

![image not found](images/sheet_view.png)

## Sheet View Navigation

When in sheet view, the following key mappings is used to navigate through the data:

| Key Combination | Action |
|-------------------------|----------------------------------------|
| `k` or `Arrow Up` | Scroll up in sheet view |
| `j` or `Arrow Down` | Scroll down in sheet view |
| `h` or `Arrow Left` | Move to the previous item in sheet view|
| `l` or `Arrow Right` | Move to the next item in sheet view |
| `g` or `Home` | Move to the first item in sheet view |
| `G` or `End` | Move to the last item in sheet view |

To go back from sheet view to table view, press `q` or `v`.

## Opening Multiple Files

If you enter multiple file names after the `tw` command, all files will open in different tabs. For instance, running the following command:

```shell
tw housing.csv user.csv
```
tw housing.csv

will open `housing.csv` and `user.csv` in separate tabs, allowing you to easily switch between them and view or compare the contentsy.

Alternatively, you can use a wildcard to open all CSV files in the directory:

```shell
tw *.csv
```

This command will load the `housing.csv` file and show the following screen:
This command will open all CSV files in the directory in separate tabs. You can then use `H` (`shift+h`) to move to the previous tab and `L` (`shift+l`) to move to the next tab.

## Query

Tabiew allows you to query your data using SQL for powerful data manipulation and analysis. To perform a query, use the `:Q` or `:query` command followed by your SQL statement. For example to query the `housing.csv` for houses priced above $500,000, located near the main road, and with at least 4 bedrooms, use the following command:

```sql
:Q SELECT * FROM housing WHERE price > 500000 AND mainroad = 'yes' AND bedrooms >= 4
```

Or to query `housing.csv` for the average area of houses grouped by the number of bedrooms and bathrooms, use the following command:

![image failed to load](images/main_page.png)
```sql
:query SELECT bedrooms, bathrooms, AVG(area) as avg_area FROM housing GROUP BY bedrooms, bathrooms
```

If it is prefered to open the results in a new tab, use the `:tabn` command followed by your SQL statement. For example:

```sql
:tabn SELECT * FROM user WHERE price > 1000000
```

The table names are their file names without the extension. For instance, the table name for `housing.csv` is `housing`. If multiple files have the same name, subsequent files will have `_2`, `_3`, and so on appended to their names. The `:schema` command shows all loaded tables.

![image not found](images/schema.png)

## Inline Query

Inline queries in Tabiew provide a convenient way to manipulate the current table. These queries are shorter version of standard SQL queries and are executed on the data currently displayed, rather than the entire dataset. Here are the commands to performe inline queries:

| Command| Example| Description|
|--------|--------|------------|
| `:S` or `:select`| `:S price, area, bedrooms, parking` | Select specific columns or functions from the current data frame. |
| `:F` or `:filter`| `:F price < 20000 AND bedrooms > 4` | Filter the current data frame, keeping rows that match the specified conditions.|
| `:O` or `:order` | `:O area` | Sort the current data frame by the specified column(s).|

For instance, the following chaing of commands:
```
:S price, area, bedrooms, parking
:F price > 20000
:F bedrooms > 4
:O area
```
is equivalent to:
```sql
SELECT price, area, bedrooms, parking
FROM housing
WHERE price > 20000 AND bedrooms > 4
ORDER BY area;
```

0 comments on commit e9fe8ad

Please sign in to comment.