import json
def limit_user_records(config_file="config.json"):
"""
Limits the output of user records for hypothesis validation based on a configuration file.
"""
try:
with open(config_file, "r") as f:
config = json.load(f)
except FileNotFoundError:
print(f"Error: Configuration file '{config_file}' not found.")
return
except json.JSONDecodeError:
print(f"Error: Invalid JSON format in '{config_file}'.")
return
limit = config.get("record_limit", 100) # Default limit to 100 records
filters = config.get("filters", {}) # Dictionary of filters
# Simulate user records (replace with your actual data source)
user_records = [
{"id": i, "name": f"User {i}", "age": i % 50, "city": f"City {i % 10}"}
for i in range(250)
]
filtered_records = []
for record in user_records:
# Apply filters
keep_record = True
for key, value in filters.items():
if key in record and record[key] != value:
keep_record = False
break
if keep_record:
filtered_records.append(record)
# Limit the output
output_records = filtered_records[:limit]
# Print the output
for record in output_records:
print(record)
if __name__ == "__main__":
limit_user_records()
Add your comment