Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasdavis committed Jan 12, 2025
1 parent fc4a25f commit 1f296cf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
42 changes: 22 additions & 20 deletions apps/registry/app/[username]/jobs-graph/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const formatTooltip = (jobInfo) => {
`${jobInfo.title || 'Untitled'} at ${jobInfo.company || 'Unknown Company'}`,
jobInfo.remote ? `${jobInfo.remote} Remote` : '',
jobInfo.location && jobInfo.location.city
? `Location: ${jobInfo.location.city}${jobInfo.location.region ? `, ${jobInfo.location.region}` : ''}`
? `Location: ${jobInfo.location.city}${
jobInfo.location.region ? `, ${jobInfo.location.region}` : ''
}`
: '',
`Type: ${jobInfo.type || 'Not specified'}`,
'',
Expand Down Expand Up @@ -174,12 +176,12 @@ export default function Jobs({ params }) {
newReadJobs.add(jobId);
localStorage.setItem(
`readJobs_${username}`,
JSON.stringify([...newReadJobs]),
JSON.stringify([...newReadJobs])
);
return newReadJobs;
});
},
[username],
[username]
);

// Memoize node colors for salary view
Expand All @@ -196,13 +198,13 @@ export default function Jobs({ params }) {
const darkBlue = [30, 64, 175]; // bg-blue-800

const r = Math.round(
lightBlue[0] + (darkBlue[0] - lightBlue[0]) * percentage,
lightBlue[0] + (darkBlue[0] - lightBlue[0]) * percentage
);
const g = Math.round(
lightBlue[1] + (darkBlue[1] - lightBlue[1]) * percentage,
lightBlue[1] + (darkBlue[1] - lightBlue[1]) * percentage
);
const b = Math.round(
lightBlue[2] + (darkBlue[2] - lightBlue[2]) * percentage,
lightBlue[2] + (darkBlue[2] - lightBlue[2]) * percentage
);

colors.set(id, `rgb(${r}, ${g}, ${b})`);
Expand All @@ -224,7 +226,7 @@ export default function Jobs({ params }) {

return readJobs.has(node.id) ? '#f1f5f9' : '#fef9c3';
},
[readJobs, filterText, filteredNodes, showSalaryGradient, nodeSalaryColors],
[readJobs, filterText, filteredNodes, showSalaryGradient, nodeSalaryColors]
);

const getNodeBackground = useCallback(
Expand All @@ -241,13 +243,13 @@ export default function Jobs({ params }) {
const darkBlue = [30, 64, 175]; // bg-blue-800

const r = Math.round(
lightBlue[0] + (darkBlue[0] - lightBlue[0]) * percentage,
lightBlue[0] + (darkBlue[0] - lightBlue[0]) * percentage
);
const g = Math.round(
lightBlue[1] + (darkBlue[1] - lightBlue[1]) * percentage,
lightBlue[1] + (darkBlue[1] - lightBlue[1]) * percentage
);
const b = Math.round(
lightBlue[2] + (darkBlue[2] - lightBlue[2]) * percentage,
lightBlue[2] + (darkBlue[2] - lightBlue[2]) * percentage
);

return `rgb(${r}, ${g}, ${b})`;
Expand All @@ -265,7 +267,7 @@ export default function Jobs({ params }) {
jobInfo,
parseSalary,
salaryRange,
],
]
);

// Function to preload and cache image
Expand Down Expand Up @@ -293,13 +295,13 @@ export default function Jobs({ params }) {
forceManyBody()
.strength(-300) // Negative values repel nodes; adjust this value for more/less repulsion
.distanceMax(600) // Maximum distance where the charge force is applied
.distanceMin(20), // Minimum distance where the charge force is applied
.distanceMin(20) // Minimum distance where the charge force is applied
);

// Add custom collision force
fg.d3Force(
'collide',
forceCollide().radius((node) => calculateCollisionRadius(node)),
forceCollide().radius((node) => calculateCollisionRadius(node))
);

setIsInitialized(true);
Expand Down Expand Up @@ -328,7 +330,7 @@ export default function Jobs({ params }) {
setActiveNode(clickedNode);
}
},
[graphData],
[graphData]
);

useEffect(() => {
Expand Down Expand Up @@ -543,7 +545,7 @@ export default function Jobs({ params }) {
// Calculate other node sizes based on relevance
else {
const jobIndex = [...mostRelevant, ...lessRelevant].findIndex(
(j) => j.uuid === node.id,
(j) => j.uuid === node.id
);
if (jobIndex !== -1) {
const maxSize = 36;
Expand All @@ -552,7 +554,7 @@ export default function Jobs({ params }) {
const totalJobs = mostRelevant.length + lessRelevant.length;
node.size = Math.max(
minSize,
maxSize - (sizeRange * jobIndex) / totalJobs,
maxSize - (sizeRange * jobIndex) / totalJobs
);
}
}
Expand Down Expand Up @@ -580,7 +582,7 @@ export default function Jobs({ params }) {
node.x - node.size,
node.y - node.size,
node.size * 2,
node.size * 2,
node.size * 2
);
ctx.strokeStyle = '#000';
ctx.lineWidth = 2;
Expand Down Expand Up @@ -610,7 +612,7 @@ export default function Jobs({ params }) {
// Draw rank number for job nodes
if (node.group !== -1) {
const jobIndex = [...mostRelevant, ...lessRelevant].findIndex(
(j) => j.uuid === node.id,
(j) => j.uuid === node.id
);
if (jobIndex !== -1) {
const fontSize = Math.max(10, node.size * 0.8);
Expand All @@ -629,7 +631,7 @@ export default function Jobs({ params }) {
ctx.font = `bold ${fontSize}px Sans-Serif`;
const textWidth = ctx.measureText(label).width;
const bckgDimensions = [textWidth, fontSize].map(
(n) => n + fontSize * 0.2,
(n) => n + fontSize * 0.2
);

// Draw background for label
Expand All @@ -642,7 +644,7 @@ export default function Jobs({ params }) {
node.y - bckgDimensions[1] * 2,
bckgDimensions[0],
bckgDimensions[1],
5,
5
);
ctx.fill();
ctx.stroke();
Expand Down
2 changes: 1 addition & 1 deletion apps/registry/app/api/similarity/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function GET(request) {
.from('resumes')
.select('username, embedding, resume')
.not('embedding', 'is', null)
.neq('username', 'thomasdavis') // Exclude thomasdavis from this query
.neq('username', 'thomasdavis') // Exclude thomasdavis from this query
.limit(limit)
.order('created_at', { ascending: false });

Expand Down
17 changes: 7 additions & 10 deletions apps/registry/pages/api/jobs-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default async function handler(req, res) {
let embedding = completion.data[0].embedding;
if (embedding.length < desiredLength) {
embedding = embedding.concat(
Array(desiredLength - embedding.length).fill(0),
Array(desiredLength - embedding.length).fill(0)
);
}

Expand Down Expand Up @@ -137,24 +137,21 @@ export default async function handler(req, res) {
// Process other jobs sequentially, each one only looking at previously processed jobs
...otherJobs.reduce((links, lessRelevantJob, index) => {
const lessRelevantVector = JSON.parse(lessRelevantJob.embedding_v5);

// Jobs to compare against: top jobs + already processed less relevant jobs
const availableJobs = [
...topJobs,
...otherJobs.slice(0, index)
];

const availableJobs = [...topJobs, ...otherJobs.slice(0, index)];

const mostSimilarJob = availableJobs.reduce(
(best, current) => {
const similarity = cosineSimilarity(
lessRelevantVector,
JSON.parse(current.embedding_v5),
JSON.parse(current.embedding_v5)
);
return similarity > best.similarity
? { job: current, similarity }
: best;
},
{ job: null, similarity: -1 },
{ job: null, similarity: -1 }
);

if (mostSimilarJob.job) {
Expand All @@ -164,7 +161,7 @@ export default async function handler(req, res) {
value: mostSimilarJob.similarity,
});
}

return links;
}, []),
],
Expand Down
7 changes: 3 additions & 4 deletions apps/registry/pages/api/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default async function handler(req, res) {

if (embedding.length < desiredLength) {
embedding = embedding.concat(
Array(desiredLength - embedding.length).fill(0),
Array(desiredLength - embedding.length).fill(0)
);
}

Expand Down Expand Up @@ -110,7 +110,7 @@ export default async function handler(req, res) {
oldest: oldestDate.toISOString(),
newest: newestDate.toISOString(),
daysBetween: Math.floor(
(newestDate - oldestDate) / (1000 * 60 * 60 * 24),
(newestDate - oldestDate) / (1000 * 60 * 60 * 24)
),
validDatesCount: validDates.length,
invalidDatesCount: jobsWithSimilarity.length - validDates.length,
Expand All @@ -121,8 +121,7 @@ export default async function handler(req, res) {

const filteredJobs = jobsWithSimilarity.filter(
(job) =>
new Date(job.created_at) >
new Date(Date.now() - 60 * 24 * 60 * 60 * 1000),
new Date(job.created_at) > new Date(Date.now() - 60 * 24 * 60 * 60 * 1000)
);

return res.status(200).send(filteredJobs);
Expand Down

0 comments on commit 1f296cf

Please sign in to comment.