Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions convex/listserv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this import required when it's unused? Genuinely asking BTW I don't use react that much haha


export default function App() {
//Example emails
const emails = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably already start putting mock data in the convex similar to what they do in the quickstart if we want

"acsu-l@list.cornell.edu",
"cs-l@cornell.edu",
"startupclub@cornell.edu",
"friend@gmail.com"
];
//Will need to be modified depending on our database schema
function detectListserv(emails) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do all functions need to be defined with useMemo in react? Or is that an anti-pattern.

const results = [];

for (const email of emails) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless of my above comment, when our state is defined with convex in the future this will probably need to be derived state with useMemo.

const username = email.split("@")[0];

if (username.includes("-l")) {
results.push("LISTSERV");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if pushing a boolean to results for detecting isListserv might be more maintainable for the future!

} else {
results.push("NOT LISTSERV");
}
}

return results;
}

const results = detectListserv(emails);

return (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Nikhill! Great work on researching the recommendation algorithms and listserv detection so far! For the future, it's good practice to try and keep the frontend and backend responsibilities more separate (i.e. only functions in the convex folder)! Of course just for prototyping and quick testing it's fine, but I think testing with just json input and printing the output to terminal is a good quick alternative just to check if your function is producing the results you want!

<div>
<h2>Email Classification</h2>
{emails.map((email, index) => (
<p key={index}>
{email} → {results[index]}
</p>
))}
</div>
);
}
74 changes: 74 additions & 0 deletions convex/reccomendation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from "react";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this import


export default function App() {
//Example profile
const userProfile = {
major: "CS",
interests: ["AI", "Startups", "Robotics"],
tags: ["machine learning", "entrepreneurship"]
};
//Example events for different listservs.
const events = [
{
id: 1,
title: "Intro to AI Workshop",
majorTags: ["CS"],
interestTags: ["AI"],
descriptionTags: ["machine learning"]
},
{
id: 2,
title: "Finance Networking Night",
majorTags: ["Econ"],
interestTags: ["Finance"],
descriptionTags: ["investment banking"]
},
{
id: 3,
title: "Startup Hackathon",
majorTags: ["CS", "Business"],
interestTags: ["Startups"],
descriptionTags: ["entrepreneurship"]
}
];

//Reccomendation algorithm will me fine tuned to match database schema decisions.
function recommendEvents(user, events) {
return events
.map(event => {
let score = 0;

if (event.majorTags.includes(user.major)) score += 3;

const interestMatches = event.interestTags.filter(tag =>
user.interests.includes(tag)
).length;

const tagMatches = event.descriptionTags.filter(tag =>
user.tags.includes(tag)
).length;

score += interestMatches * 2;
score += tagMatches * 2;

return { ...event, score };
})
.filter(event => event.score > 0)
.sort((a, b) => b.score - a.score);
}

const recommended = recommendEvents(userProfile, events);

return (
<div style={{ padding: "20px" }}>
<h2>Recommended Events</h2>

{recommended.map(event => (
<div key={event.id} style={{ marginBottom: "10px" }}>
<strong>{event.title}</strong>
<p>Score: {event.score}</p>
</div>
))}
</div>
);
}
Loading