Drop support for Ledger as a separate content type

Khoj will soon get a generic text indexing content type. This along
with a file filter should suffice for searching through Ledger
transactions, if required.

Having a specific content type for niche use-case like ledger isn't
useful. Removing unused content types will reduce khoj code to manage.
This commit is contained in:
Debanjum Singh Solanky
2023-07-02 16:49:51 -07:00
parent c9db5321e7
commit 0f993b332e
19 changed files with 18 additions and 635 deletions

View File

@@ -1,233 +0,0 @@
; -*- mode: org; mode: beancount; -*-
;; Otzi's Ledger: A 3rd Millenium B.C Mountain Shepherd's Ledger
;;
;; A stylized recreation of Otzi's transaction history from a few months before his death
;; based on https://en.wikipedia.org/wiki/Otzi#Scientific_analyses
* Options ; Beancount options
#+STARTUP: content
option "title" "Beancount Ledger"
option "operating_currency" "COWRIE" ; The main currencies you use
* Accounts ; Open all the accounts
3300-04-01 open Equity:Sheep ANIMALS
description: "Inheritance from Parents"
3300-04-01 open Income:Hunt ANIMALS
description: "From Hunting Animals"
3300-04-01 open Income:Forage PLANTS
description: "From Foraging Wild Fruits, Plants"
3300-04-01 open Income:Market COWRIE
description: "Assets sold at the market"
3300-04-01 open Assets:Animal ANIMALS
description: "Animals Owned Like Sheep, Goats, Cows"
3300-04-01 open Assets:Food MEALS
description: "Food for Consumption"
3300-04-01 open Assets:Food:Meat MEALS
description: "Killed Animals for Consumption"
3300-04-01 open Assets:Food:Veggie MEALS
description: "Procured, Foraged Fruits, Grains"
3300-04-01 open Assets:Plant PLANTS
description: "Procured, Foraged Plants"
3300-04-01 open Assets:Tools TOOLS
description: "Procured, Made Tools"
3300-04-01 open Assets:Cash COWRIE
description: "Cowrie Shells in Pouch"
3300-04-01 open Expenses:Medicine COWRIE
description: "Procured, Foraged Medicinals"
3300-04-01 open Expenses:Tools:Weapons COWRIE
description: "Bought Weapons"
3300-04-01 open Expenses:Food
description: "Bought, Consumed Meals"
3300-04-01 open Expenses:Clothing COWRIE
description: "Bought Clothes"
3300-04-01 open Expenses:Tools COWRIE
description: "Bought Tools"
* Transactions
3345-03-15 * "Parents" "Inheritance"
note: "Opening Balance"
Equity:Sheep -20 ANIMALS
Assets:Animal
3345-03-26 * "Hauslabjoch Pass, Otzal Alps" "Red Deers"
Income:Hunt -2 ANIMALS {50 COWRIE}
Assets:Food:Meat 10 MEALS {7.5 COWRIE, "Deer"}
Assets:Animal 0.5 ANIMALS {50 COWRIE}
3345-03-28 * "Hauslabjoch Pass, Otzal Alps" "Wild Berries"
Income:Forage -60 PLANTS
Assets:Food:Veggie 3 MEALS {20 PLANTS, "Berry"}
3345-04-02 * "Hauslabjoch Pass, Otzal Alps" "Last Weeks Meals"
Assets:Food:Meat -7 MEALS {7.5 COWRIE, "Deer"}
Assets:Food:Veggie -3 MEALS {20 PLANTS, "Berry"}
Expenses:Food
3345-04-02 * "Hauslabjoch Pass, Otzal Alps" "Sloe"
Income:Forage -50 PLANTS
Assets:Food:Veggie 5 MEALS {10 PLANTS, "Sloe"}
3345-04-05 * "Hauslabjoch Pass, Otzal Alps" "Ibex"
Income:Hunt -2 ANIMALS {100 COWRIE}
Assets:Food:Meat 10 MEALS {15 COWRIE, "Ibex"}
Assets:Animal 0.5 ANIMALS {100 COWRIE}
3345-04-08 * "Hauslabjoch Pass, Otzal Alps" "Birch Fungus Medicinal Mushroom"
Income:Forage -6 PLANTS {100 COWRIE}
Assets:Plant 6 PLANTS {100 COWRIE}
3345-04-09 * "Hauslabjoch Pass, Otzal Alps" "Last Weeks Meals"
Assets:Food:Meat -3 MEALS {7.5 COWRIE, "Deer"}
Assets:Food:Meat -4 MEALS {15 COWRIE, "Ibex"}
Assets:Food:Veggie -3 MEALS {10 PLANTS, "Sloe"}
Expenses:Food
3345-04-15 * "Innsbruck Farmers Market" "Sold Red Deers Skin, Antler"
Assets:Animal -0.5 ANIMALS {50 COWRIE}
Assets:Cash 25 COWRIE
3345-04-15 * "Innsbruck Farmers Market" "Sold Ibex Skin, Antler"
Assets:Animal -0.5 ANIMALS {100 COWRIE}
Assets:Cash 50 COWRIE
3345-04-15 * "Innsbruck Farmers Market" "Sold Birch Fungus Medicinal Mushroom"
Assets:Plant -5 PLANTS {100 COWRIE}
Assets:Cash 500 COWRIE
3345-04-15 * "Innsbruck Farmers Market" "Snow Shoes: Bearskin, Deer hide, Tree Bark"
note: "Expensive Bearkskin but need not want"
Assets:Cash -90 COWRIE
Expenses:Clothing
3345-04-15 * "Innsbruck Farmers Market" "Soft Grass Socks"
Assets:Cash -10 COWRIE
Expenses:Clothing
3345-04-15 * "Innsbruck Farmers Market" "Cattle Shoelace"
Assets:Cash -5 COWRIE
Expenses:Clothing
3345-04-15 * "Innsbruck Farmers Market" "Einkorn Wheat Bran Bread"
Assets:Cash -50 COWRIE
Assets:Food:Veggie 5 MEALS {10 COWRIE, "Bread"}
3345-04-16 * "Enroute to Innsbruck" "Last Weeks Meals"
Assets:Food:Meat -6 MEALS {15 COWRIE, "Ibex"}
Assets:Food:Veggie -2 MEALS {10 PLANTS, "Sloe"}
Expenses:Food
3345-04-16 * "Innsbruck Tools Market" "Firelighting Kit: Plants, Pyrite, Flint"
Assets:Cash -30 COWRIE
Expenses:Tools
3345-04-16 * "Innsbruck Tools Market" "Flint Blade, Ash Handle Knife"
Assets:Cash -50 COWRIE
Expenses:Tools:Weapons
3345-04-20 * "Tisenjoch Pass, Otzal Alps" "Chamois"
Income:Hunt -1 ANIMALS {100 COWRIE}
Assets:Food:Meat 5 MEALS {10 COWRIE, "Chamois"}
Assets:Animal 0.5 ANIMALS {100 COWRIE}
3345-04-22 * "Tisenjoch Pass, Otzal Alps" "Roe Deer"
Income:Hunt -2 ANIMALS {50 COWRIE}
Assets:Food:Meat 10 MEALS {7.5 COWRIE, "Deer"}
Assets:Animal 0.5 ANIMALS {50 COWRIE}
3345-04-23 * "Tisenjoch Pass, Otzal Alps" "Last Weeks Meals"
Assets:Food:Veggie -4 MEALS {10 COWRIE, "Bread"}
Assets:Food:Meat -4 MEALS {10 COWRIE, "Chamois"}
Assets:Food:Meat -3 MEALS {7.5 COWRIE, "Deer"}
Expenses:Food
3345-04-25 * "Tisenjoch Pass, Otzal Alps" "Roe Deer Quiver"
Assets:Animal -0.25 ANIMALS {50 COWRIE}
Assets:Tools 1 TOOLS {12.50 COWRIE}
3345-04-28 * "Tisenjoch Pass, Otzal Alps" "Wild Berries"
Income:Forage -60 PLANTS
Assets:Food:Veggie 3 MEALS {20 PLANTS, "Berry"}
3345-04-30 * "Tisenjoch Pass, Otzal Alps" "Last Weeks Meals"
Assets:Food:Veggie -1 MEALS {10 COWRIE, "Bread"}
Assets:Food:Meat -1 MEALS {10 COWRIE, "Chamois"}
Assets:Food:Meat -6 MEALS {7.5 COWRIE, "Deer"}
Expenses:Food
3345-05-02 * "Enroute to Bolzano City" "Poppy Seed"
Income:Forage -80 PLANTS
Assets:Food:Veggie 8 MEALS {10 PLANTS, "Poppy"}
3345-05-06 * "Enroute to Bolzano City" "Barley, Flax Seeds"
Income:Forage -80 PLANTS
Assets:Food:Veggie 4 MEALS {10 PLANTS, "Barley"}
Assets:Food:Veggie 4 MEALS {10 PLANTS, "Flax"}
3345-05-07 * "Enroute to Bolzano City" "Last Weeks Meals"
Assets:Food:Veggie -5 MEALS {10 PLANTS, "Poppy"}
Assets:Food:Veggie -3 MEALS {20 PLANTS, "Berry"}
Assets:Food:Meat -1 MEALS {7.5 COWRIE, "Deer"}
Expenses:Food
3345-05-09 * "Bolzano City Market" "Sold Roe Deers Hide"
Assets:Animal -0.25 ANIMALS {50 COWRIE}
Assets:Cash 12.5 COWRIE
3345-05-09 * "Bolzano City Market" "Sold Chamois Hide"
Assets:Animal -0.5 ANIMALS {100 COWRIE}
Assets:Cash 50 COWRIE
3345-05-10 * "Bolzano City Market" "Yewood Handle Copper Axe"
note: "Expensive Bearkskin but need not want"
Assets:Cash -140 COWRIE
Expenses:Tools:Weapons
3345-05-10 * "Bolzano City Market" "Sheepskin Hide Coat"
Assets:Cash -40 COWRIE
Expenses:Clothing
3345-05-10 * "Bolzano City Market" "Sheepskin Loincloth"
Assets:Cash -20 COWRIE
Expenses:Clothing
3345-05-10 * "Bolzano City Market" "Goat Skin Leggings"
Assets:Cash -40 COWRIE
Expenses:Clothing
3345-05-10 * "Bolzano City Market" "Brown Bear Fur Hat"
Assets:Cash -60 COWRIE
Expenses:Clothing
3345-05-10 * "Bolzano City Market" "Viburnum, Dogwood, Flint"
note: "For Making Arrows"
Assets:Cash -40 COWRIE
Expenses:Tools:Weapons
3345-05-10 * "Bolzano City Market" "Yew Wood"
note: "For Making Yewood Longbow"
Assets:Cash -32.5 COWRIE
Expenses:Tools:Weapons
3345-05-10 * "Bolzano City Market" "Birch Bark Baskets"
note: "Need Better Containers for Storage, Carrying"
Assets:Cash -30 COWRIE
Expenses:Tools
3345-05-13 * "Near Feldthurns, South Tyrol" "Ibex"
Income:Hunt -2 ANIMALS {100 COWRIE}
Assets:Food:Meat 10 MEALS {15 COWRIE, "Ibex"}
Assets:Animal 0.5 ANIMALS {100 COWRIE}
3345-05-14 * "Near Feldthurns, South Tyrol" "Last Weeks Meals"
Assets:Food:Veggie -4 MEALS {10 PLANTS, "Barley"}
Assets:Food:Veggie -3 MEALS {10 PLANTS, "Flax"}
Assets:Food:Veggie -3 MEALS {10 PLANTS, "Poppy"}
Expenses:Food
3345-05-21 * "Fineilspitze Peak, Otzal Alps" "Last Weeks Meals"
Assets:Food:Meat -7 MEALS {15 COWRIE, "Ibex"}
Assets:Food:Veggie -1 MEALS {10 PLANTS, "Flax"}
Expenses:Food

View File

@@ -1,18 +0,0 @@
* The Beatles - Across The Universe :60s:BRITISH:POP:
:PROPERTIES:
:TYPE: song
:END:
:LOGBOOK:
ENQUEUED: [1984-04-01 Sun 00:00]
:END:
* Ram Narayan :INDIAN:CLASSICAL:SARANGI:
** Ram Narayan - Raag Kirwani Alap
:PROPERTIES:
:TYPE: song
:QUERY: Raga Kirvani (feat. Suresh Talwalkar, François Auboux) (Alap)
:CATEGORY: youtube
:END:
:LOGBOOK:
ENQUEUED: [1984-04-01 Sun 00:00]
:END:

View File

@@ -1,118 +0,0 @@
# Standard Packages
import json
# Internal Packages
from khoj.processor.ledger.beancount_to_jsonl import BeancountToJsonl
def test_no_transactions_in_file(tmp_path):
"Handle file with no transactions."
# Arrange
entry = f"""
- Bullet point 1
- Bullet point 2
"""
beancount_file = create_file(tmp_path, entry)
# Act
# Extract Entries from specified Beancount files
entry_nodes, file_to_entries = BeancountToJsonl.extract_beancount_transactions(beancount_files=[beancount_file])
# Process Each Entry from All Beancount Files
jsonl_string = BeancountToJsonl.convert_transaction_maps_to_jsonl(
BeancountToJsonl.convert_transactions_to_maps(entry_nodes, file_to_entries)
)
jsonl_data = [json.loads(json_string) for json_string in jsonl_string.splitlines()]
# Assert
assert len(jsonl_data) == 0
def test_single_beancount_transaction_to_jsonl(tmp_path):
"Convert transaction from single file to jsonl."
# Arrange
entry = f"""
1984-04-01 * "Payee" "Narration"
Expenses:Test:Test 1.00 KES
Assets:Test:Test -1.00 KES
"""
beancount_file = create_file(tmp_path, entry)
# Act
# Extract Entries from specified Beancount files
entries, entry_to_file_map = BeancountToJsonl.extract_beancount_transactions(beancount_files=[beancount_file])
# Process Each Entry from All Beancount Files
jsonl_string = BeancountToJsonl.convert_transaction_maps_to_jsonl(
BeancountToJsonl.convert_transactions_to_maps(entries, entry_to_file_map)
)
jsonl_data = [json.loads(json_string) for json_string in jsonl_string.splitlines()]
# Assert
assert len(jsonl_data) == 1
def test_multiple_transactions_to_jsonl(tmp_path):
"Convert multiple transactions from single file to jsonl."
# Arrange
entry = f"""
1984-04-01 * "Payee" "Narration"
Expenses:Test:Test 1.00 KES
Assets:Test:Test -1.00 KES
\t\r
1984-04-01 * "Payee" "Narration"
Expenses:Test:Test 1.00 KES
Assets:Test:Test -1.00 KES
"""
beancount_file = create_file(tmp_path, entry)
# Act
# Extract Entries from specified Beancount files
entries, entry_to_file_map = BeancountToJsonl.extract_beancount_transactions(beancount_files=[beancount_file])
# Process Each Entry from All Beancount Files
jsonl_string = BeancountToJsonl.convert_transaction_maps_to_jsonl(
BeancountToJsonl.convert_transactions_to_maps(entries, entry_to_file_map)
)
jsonl_data = [json.loads(json_string) for json_string in jsonl_string.splitlines()]
# Assert
assert len(jsonl_data) == 2
def test_get_beancount_files(tmp_path):
"Ensure Beancount files specified via input-filter, input-files extracted"
# Arrange
# Include via input-filter globs
group1_file1 = create_file(tmp_path, filename="group1-file1.bean")
group1_file2 = create_file(tmp_path, filename="group1-file2.bean")
group2_file1 = create_file(tmp_path, filename="group2-file1.beancount")
group2_file2 = create_file(tmp_path, filename="group2-file2.beancount")
# Include via input-file field
file1 = create_file(tmp_path, filename="ledger.bean")
# Not included by any filter
create_file(tmp_path, filename="not-included-ledger.bean")
create_file(tmp_path, filename="not-included-text.txt")
expected_files = sorted(map(str, [group1_file1, group1_file2, group2_file1, group2_file2, file1]))
# Setup input-files, input-filters
input_files = [tmp_path / "ledger.bean"]
input_filter = [tmp_path / "group1*.bean", tmp_path / "group2*.beancount"]
# Act
extracted_org_files = BeancountToJsonl.get_beancount_files(input_files, input_filter)
# Assert
assert len(extracted_org_files) == 5
assert extracted_org_files == expected_files
# Helper Functions
def create_file(tmp_path, entry=None, filename="ledger.beancount"):
beancount_file = tmp_path / filename
beancount_file.touch()
if entry:
beancount_file.write_text(entry)
return beancount_file

View File

@@ -34,7 +34,7 @@ def test_search_with_invalid_content_type(client):
# ----------------------------------------------------------------------------------------------------
def test_search_with_valid_content_type(client):
for content_type in ["all", "org", "markdown", "ledger", "image", "pdf", "plugin1"]:
for content_type in ["all", "org", "markdown", "image", "pdf", "plugin1"]:
# Act
response = client.get(f"/api/search?q=random&t={content_type}")
# Assert
@@ -52,7 +52,7 @@ def test_update_with_invalid_content_type(client):
# ----------------------------------------------------------------------------------------------------
def test_update_with_valid_content_type(client):
for content_type in ["org", "markdown", "ledger", "image", "pdf", "plugin1"]:
for content_type in ["org", "markdown", "image", "pdf", "plugin1"]:
# Act
response = client.get(f"/api/update?t={content_type}")
# Assert
@@ -70,7 +70,7 @@ def test_regenerate_with_invalid_content_type(client):
# ----------------------------------------------------------------------------------------------------
def test_regenerate_with_valid_content_type(client):
for content_type in ["org", "markdown", "ledger", "image", "pdf", "plugin1"]:
for content_type in ["org", "markdown", "image", "pdf", "plugin1"]:
# Act
response = client.get(f"/api/update?force=true&t={content_type}")
# Assert