Skip to content

Commit

Permalink
Merge pull request #153 from digital-land/add_severity
Browse files Browse the repository at this point in the history
Adding severity column functionality in log
  • Loading branch information
ssadhu-sl authored Nov 23, 2023
2 parents 7dcf8c6 + 296df0d commit 0a8677f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
23 changes: 23 additions & 0 deletions digital_land/log.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import csv
from datetime import datetime
import pandas as pd


def entry_date():
Expand Down Expand Up @@ -54,6 +55,28 @@ def log_issue(self, fieldname, issue_type, value, line_number=0, entry_number=0)
}
)

def add_severity_column(self, severity_mapping_path):
# Load only the 'severity' column from severity_mapping
severity_mapping = pd.read_csv(
severity_mapping_path, usecols=["issue-type", "severity"]
)

# Convert the existing log data to a DataFrame
log_df = pd.DataFrame(self.rows)

# Merge with severity_mapping based on 'issue-type'
merged_df = pd.merge(
log_df,
severity_mapping,
how="left",
left_on="issue-type",
right_on="issue-type",
)

# Add the new 'severity' column to the log data
self.fieldnames.append("severity")
self.rows = merged_df.to_dict(orient="records")


class ColumnFieldLog(Log):
fieldnames = ["entry-date", "dataset", "resource", "column", "field"]
Expand Down
3 changes: 3 additions & 0 deletions tests/data/specification/issue-type.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
issue-type,severity,name,description,responsibility
type1,sev1,test,desc1,internal
type2,sev2,test,desc2,internal
23 changes: 23 additions & 0 deletions tests/unit/test_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest
from digital_land.log import IssueLog

test_collection_dir = "tests/data"


@pytest.fixture
def sample_issue_log_csv_path():
return test_collection_dir + "/specification/issue-type.csv"


def test_add_severity_column(sample_issue_log_csv_path):
issue = IssueLog()
issue.log_issue("tesr", "type1", "value1")

# Confirm 'severity' field is not added to the fieldnames beforehand
assert "severity" not in issue.fieldnames

issue.add_severity_column(sample_issue_log_csv_path)

# Check if the 'severity' field is added to fieldnames
assert "severity" in issue.fieldnames
assert issue.rows[0]["severity"] == "sev1"

0 comments on commit 0a8677f

Please sign in to comment.