Skip to content

Commit

Permalink
Create data_collection.py (#385)
Browse files Browse the repository at this point in the history
#362 
Description
<!–Please include a brief description of the changes–> Added data
collection and recommendation model features. The data collection tracks
user interactions (clicks, views, purchases) and stores them in a
database. The recommendation model uses collaborative filtering and
content-based filtering to provide personalized recommendations.

Related Issues
<!–Cite any related issue(s) this pull request addresses. If none,
simply state “None”–>

Closes #123 (Replace with the actual issue number if applicable)
Type of PR
<!-- Mention PR Type according to the issue in brackets below and check
the below box -->

[ ] Feature
Screenshots / videos (if applicable)
<!–Attach any relevant screenshots or videos demonstrating the changes–>
N/A

Checklist
<!-- [X] - put a cross/X inside [] to check the box -->

[X] I have gone through the contributing guide
[X] I have updated my branch and synced it with project main branch
before making this PR
[X] I have performed a self-review of my code
[X] I have tested the changes thoroughly before submitting this pull
request.
[X] I have provided relevant issue numbers, screenshots, and videos
after making the changes.
[X] I have commented my code, particularly in hard-to-understand areas.
Additional context:
<!–Include any additional information or context that might be helpful
for reviewers.–> This feature enhances user experience by providing
personalized recommendations and insights into user behavior, which can
inform marketing strategies and inventory management.
  • Loading branch information
Anjaliavv51 authored Oct 15, 2024
2 parents 585d26b + f883dc2 commit 4aa2ab2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions data_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from datetime import datetime
import sqlite3

# Connect to SQLite database
conn = sqlite3.connect('user_data.db')
cursor = conn.cursor()

# Create table
cursor.execute('''
CREATE TABLE IF NOT EXISTS user_interactions (
user_id INTEGER,
item_id INTEGER,
interaction_type TEXT,
timestamp DATETIME
)
''')

# Function to log interaction
def log_interaction(user_id, item_id, interaction_type):
timestamp = datetime.now()
cursor.execute('''
INSERT INTO user_interactions (user_id, item_id, interaction_type, timestamp)
VALUES (?, ?, ?, ?)
''', (user_id, item_id, interaction_type, timestamp))
conn.commit()

# Example usage
log_interaction(1, 101, 'click')
log_interaction(1, 102, 'view')
log_interaction(2, 101, 'purchase')

0 comments on commit 4aa2ab2

Please sign in to comment.