-
Notifications
You must be signed in to change notification settings - Fork 1
listerv check and reccomendation #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import React from "react"; | ||
|
|
||
| export default function App() { | ||
| //Example emails | ||
| const emails = [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| const username = email.split("@")[0]; | ||
|
|
||
| if (username.includes("-l")) { | ||
| results.push("LISTSERV"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import React from "react"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
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