A report can have correct arithmetic and still be misleading. If automated activity and human visits enter the same total, a reader may interpret every session as a potential customer.
This example keeps three supplied labels separate: automated, human and unknown. It validates a small CSV and returns one total for each label. It does not detect bots or decide whether a visitor is human. Those labels must come from evidence you maintain outside this script.
Disclosure: this guide is published by the operator of Traffic Bot, which provides CTR software for SEO agencies. An AI agent drafted this guide and code; the example and validation cases were run locally before publication.
1. Define the input contract
Save the following fictional data as sessions.csv:
activity_class,sessions
automated,120
human,80
unknown,20
automated,120
Each row represents an aggregate from the same reporting window. The sessions value is a non-negative integer, and the label describes the evidence available for that aggregate. Do not relabel uncertain activity as human merely because you cannot identify it as automated. Use unknown when the classification is unresolved.
Use mutually exclusive aggregates. If the same sessions appear in two rows from different exports, this script will add both rows; it cannot identify the overlap. Deduplicate or reconcile the inputs before summarizing them.
2. Validate before adding
Save this as session_totals.py:
import csv
import sys
CLASSES = ("automated", "human", "unknown")
def summarize(path):
totals = {kind: 0 for kind in CLASSES}
with open(path, newline="", encoding="utf-8") as source:
rows = csv.DictReader(source)
if rows.fieldnames != ["activity_class", "sessions"]:
raise ValueError("Expected activity_class,sessions headers")
for line, row in enumerate(rows, start=2):
kind = (row.get("activity_class") or "").strip()
count = (row.get("sessions") or "").strip()
if None in row or kind not in totals:
raise ValueError(f"Invalid class or extra field on line {line}")
if not (count.isascii() and count.isdecimal()):
raise ValueError(f"Expected non-negative integer on line {line}")
totals[kind] += int(count)
return totals
if __name__ == "__main__":
for kind, count in summarize(sys.argv[1]).items():
print(f"{kind}: {count}")
Python’s csv.DictReader maps a CSV row to header names. The code opens the file with newline="", checks the exact two-column header and rejects extra fields, unexpected labels, missing counts and non-integer counts.
This is a small reporting example, not a full ingestion pipeline. It stops on the first invalid row. In a larger workflow, capture the error alongside the input file and fix the source data rather than silently dropping the row.
3. Run the example
python3 session_totals.py sessions.csv
Output from the local run:
automated: 240
human: 80
unknown: 20
The two automated rows add to 240. The other totals remain separate. These numbers are fictional sample data, not product results or customer figures.
The validation checks also rejected a negative count, a decimal count, an unsupported label, an empty count, an extra field and duplicate headers. Try one of those inputs and the script should raise ValueError rather than produce a plausible total from invalid data.
4. Keep the report’s claims as narrow as the data
A total labelled human still does not prove purchase intent or a sale. Record enquiries and completed purchases from their own evidence. Likewise, an automated-session total does not establish an improvement in search visibility.
Include the reporting dates, source files and classification method when you hand the totals to another person. If the inputs combine different time windows or inconsistent classification rules, correcting the arithmetic will not fix the comparison.
Traffic Bot runs automated Google search-and-visit sessions for indexed client pages already appearing within the Top 100 for a chosen keyword. Campaigns use the Traffic Creator account and SEO Wallet. These sessions are automated, not human customers, and rankings or sales are not guaranteed. The product’s current offer and operator details are available at traffic-bot.com.
Top comments (0)