Sports scalp 1.0

This commit is contained in:
Flatlogic Bot 2026-02-04 00:33:29 +00:00
parent acf82d96bd
commit cbc42e03c7
3 changed files with 343 additions and 146 deletions

View File

@ -7,6 +7,11 @@ const menuAside: MenuAsideItem[] = [
icon: icon.mdiViewDashboardOutline,
label: 'Dashboard',
},
{
href: '/insights',
icon: icon.mdiRobot,
label: 'AI Insights',
},
{
href: '/users/users-list',
@ -136,4 +141,4 @@ const menuAside: MenuAsideItem[] = [
},
]
export default menuAside
export default menuAside

View File

@ -1,166 +1,130 @@
import React, { useEffect, useState } from 'react';
import type { ReactElement } from 'react';
import Head from 'next/head';
import Link from 'next/link';
import BaseButton from '../components/BaseButton';
import CardBox from '../components/CardBox';
import SectionFullScreen from '../components/SectionFullScreen';
import LayoutGuest from '../layouts/Guest';
import BaseDivider from '../components/BaseDivider';
import BaseButtons from '../components/BaseButtons';
import { getPageTitle } from '../config';
import { useAppSelector } from '../stores/hooks';
import CardBoxComponentTitle from "../components/CardBoxComponentTitle";
import { getPexelsImage, getPexelsVideo } from '../helpers/pexels';
import { getPexelsImage } from '../helpers/pexels';
import * as icon from '@mdi/js';
import BaseIcon from '../components/BaseIcon';
export default function Starter() {
const [illustrationImage, setIllustrationImage] = useState({
src: undefined,
photographer: undefined,
photographer_url: undefined,
})
const [illustrationVideo, setIllustrationVideo] = useState({video_files: []})
const [contentType, setContentType] = useState('video');
const [contentPosition, setContentPosition] = useState('left');
export default function LandingPage() {
const [bgImage, setBgImage] = useState('');
const textColor = useAppSelector((state) => state.style.linkColor);
const title = 'App Draft'
// Fetch Pexels image/video
useEffect(() => {
async function fetchData() {
const image = await getPexelsImage();
const video = await getPexelsVideo();
setIllustrationImage(image);
setIllustrationVideo(video);
async function fetchBg() {
const image = await getPexelsImage('basketball court dark');
if (image?.src?.large2x) {
setBgImage(image.src.large2x);
}
}
fetchData();
fetchBg();
}, []);
const imageBlock = (image) => (
<div
className='hidden md:flex flex-col justify-end relative flex-grow-0 flex-shrink-0 w-1/3'
style={{
backgroundImage: `${
image
? `url(${image?.src?.original})`
: 'linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5))'
}`,
backgroundSize: 'cover',
backgroundPosition: 'left center',
backgroundRepeat: 'no-repeat',
}}
>
<div className='flex justify-center w-full bg-blue-300/20'>
<a
className='text-[8px]'
href={image?.photographer_url}
target='_blank'
rel='noreferrer'
>
Photo by {image?.photographer} on Pexels
</a>
return (
<div className="bg-[#0B0E14] min-h-screen text-white overflow-x-hidden font-sans">
<Head>
<title>{getPageTitle('SportScalp AI - Professional Sports Analytics')}</title>
</Head>
{/* Hero Section */}
<div className="relative h-screen flex items-center justify-center">
{/* Background Overlay */}
<div
className="absolute inset-0 z-0 opacity-30 bg-cover bg-center transition-opacity duration-1000"
style={{ backgroundImage: `url(${bgImage || 'https://images.pexels.com/photos/1080884/pexels-photo-1080884.jpeg'})` }}
/>
<div className="absolute inset-0 z-10 bg-gradient-to-b from-transparent via-[#0B0E14]/80 to-[#0B0E14]" />
<div className="relative z-20 text-center px-4 max-w-4xl">
<div className="inline-flex items-center space-x-2 bg-[#CCFF00] text-black px-4 py-1 rounded-full text-xs font-bold mb-6 animate-pulse">
<BaseIcon path={icon.mdiFlash} size={14} />
<span>POWERED BY AI</span>
</div>
<h1 className="text-5xl md:text-7xl font-extrabold mb-6 tracking-tight">
UNCOVER THE <span className="text-[#CCFF00]">WINNING</span> EDGE
</h1>
<p className="text-lg md:text-xl text-gray-400 mb-10 max-w-2xl mx-auto leading-relaxed">
The world&apos;s most advanced sports data scalper. Ask questions, analyze betting lines, and get real-time insights for NBA, NFL, and NHL.
</p>
<div className="flex flex-col md:flex-row items-center justify-center space-y-4 md:space-y-0 md:space-x-4">
<BaseButton
href="/login"
label="Launch Terminal"
color="info"
className="w-full md:w-auto px-10 py-4 text-lg font-bold rounded-xl bg-[#CCFF00] hover:bg-[#b8e600] text-black border-none"
/>
<BaseButton
href="/register"
label="Create Account"
color="whiteDark"
className="w-full md:w-auto px-10 py-4 text-lg font-bold rounded-xl border-gray-700 text-white"
/>
</div>
</div>
</div>
{/* Features Section */}
<div className="py-24 px-4 bg-[#0B0E14]">
<div className="max-w-6xl mx-auto grid grid-cols-1 md:grid-cols-3 gap-12">
<div className="flex flex-col items-center text-center p-8 rounded-3xl bg-[#1F2937]/50 border border-gray-800 hover:border-[#CCFF00]/50 transition-all">
<div className="w-16 h-16 bg-[#CCFF00]/10 rounded-2xl flex items-center justify-center mb-6">
<BaseIcon path={icon.mdiRobot} size={32} className="text-[#CCFF00]" />
</div>
<h3 className="text-xl font-bold mb-4">Natural Language Query</h3>
<p className="text-gray-400 text-sm">
&quot;Show me players with 70% 3PT accuracy in their last 15 games.&quot; Just ask, and our AI does the math.
</p>
</div>
<div className="flex flex-col items-center text-center p-8 rounded-3xl bg-[#1F2937]/50 border border-gray-800 hover:border-[#CCFF00]/50 transition-all">
<div className="w-16 h-16 bg-[#CCFF00]/10 rounded-2xl flex items-center justify-center mb-6">
<BaseIcon path={icon.mdiDatabaseSearch} size={32} className="text-[#CCFF00]" />
</div>
<h3 className="text-xl font-bold mb-4">Multi-Source Scalping</h3>
<p className="text-gray-400 text-sm">
Real-time data from StatMuse, NBA, NFL, and NHL official sources, and major betting platforms.
</p>
</div>
<div className="flex flex-col items-center text-center p-8 rounded-3xl bg-[#1F2937]/50 border border-gray-800 hover:border-[#CCFF00]/50 transition-all">
<div className="w-16 h-16 bg-[#CCFF00]/10 rounded-2xl flex items-center justify-center mb-6">
<BaseIcon path={icon.mdiChartLineVariant} size={32} className="text-[#CCFF00]" />
</div>
<h3 className="text-xl font-bold mb-4">Line Relevance Engine</h3>
<p className="text-gray-400 text-sm">
Automatically cross-reference player performance with betting lines to find high-value opportunities.
</p>
</div>
</div>
</div>
{/* CTA Section */}
<div className="py-24 px-4 bg-gradient-to-r from-[#0B0E14] to-[#1F2937]">
<div className="max-w-4xl mx-auto text-center">
<h2 className="text-3xl md:text-5xl font-bold mb-8 italic">READY TO <span className="text-[#CCFF00]">DOMINATE</span> THE DATA?</h2>
<Link href="/login" className="inline-block bg-[#CCFF00] text-black px-12 py-4 rounded-xl font-black text-xl hover:scale-105 transition-transform">
GET STARTED NOW
</Link>
</div>
</div>
{/* Footer */}
<footer className="py-12 px-4 border-t border-gray-800 text-center text-gray-500 text-sm">
<p>© 2026 SportScalp AI. All rights reserved.</p>
<div className="flex justify-center space-x-6 mt-4">
<Link href="/terms-of-use" className="hover:text-white transition-colors">Terms</Link>
<Link href="/privacy-policy" className="hover:text-white transition-colors">Privacy</Link>
</div>
</footer>
</div>
);
const videoBlock = (video) => {
if (video?.video_files?.length > 0) {
return (
<div className='hidden md:flex flex-col justify-end relative flex-grow-0 flex-shrink-0 w-1/3'>
<video
className='absolute top-0 left-0 w-full h-full object-cover'
autoPlay
loop
muted
>
<source src={video?.video_files[0]?.link} type='video/mp4'/>
Your browser does not support the video tag.
</video>
<div className='flex justify-center w-full bg-blue-300/20 z-10'>
<a
className='text-[8px]'
href={video?.user?.url}
target='_blank'
rel='noreferrer'
>
Video by {video.user.name} on Pexels
</a>
</div>
</div>)
}
};
return (
<div
style={
contentPosition === 'background'
? {
backgroundImage: `${
illustrationImage
? `url(${illustrationImage.src?.original})`
: 'linear-gradient(rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.5))'
}`,
backgroundSize: 'cover',
backgroundPosition: 'left center',
backgroundRepeat: 'no-repeat',
}
: {}
}
>
<Head>
<title>{getPageTitle('Starter Page')}</title>
</Head>
<SectionFullScreen bg='violet'>
<div
className={`flex ${
contentPosition === 'right' ? 'flex-row-reverse' : 'flex-row'
} min-h-screen w-full`}
>
{contentType === 'image' && contentPosition !== 'background'
? imageBlock(illustrationImage)
: null}
{contentType === 'video' && contentPosition !== 'background'
? videoBlock(illustrationVideo)
: null}
<div className='flex items-center justify-center flex-col space-y-4 w-full lg:w-full'>
<CardBox className='w-full md:w-3/5 lg:w-2/3'>
<CardBoxComponentTitle title="Welcome to your App Draft app!"/>
<div className="space-y-3">
<p className='text-center '>This is a React.js/Node.js app generated by the <a className={`${textColor}`} href="https://flatlogic.com/generator">Flatlogic Web App Generator</a></p>
<p className='text-center '>For guides and documentation please check
your local README.md and the <a className={`${textColor}`} href="https://flatlogic.com/documentation">Flatlogic documentation</a></p>
</div>
<BaseButtons>
<BaseButton
href='/login'
label='Login'
color='info'
className='w-full'
/>
</BaseButtons>
</CardBox>
</div>
</div>
</SectionFullScreen>
<div className='bg-black text-white flex flex-col text-center justify-center md:flex-row'>
<p className='py-6 text-sm'>© 2026 <span>{title}</span>. All rights reserved</p>
<Link className='py-6 ml-4 text-sm' href='/privacy-policy/'>
Privacy Policy
</Link>
</div>
</div>
);
}
Starter.getLayout = function getLayout(page: ReactElement) {
return <LayoutGuest>{page}</LayoutGuest>;
};
LandingPage.getLayout = function getLayout(page: ReactElement) {
return <LayoutGuest>{page}</LayoutGuest>;
};

View File

@ -0,0 +1,228 @@
import * as icon from '@mdi/js';
import Head from 'next/head';
import React, { useState } from 'react';
import type { ReactElement } from 'react';
import LayoutAuthenticated from '../layouts/Authenticated';
import SectionMain from '../components/SectionMain';
import SectionTitleLineWithButton from '../components/SectionTitleLineWithButton';
import CardBox from '../components/CardBox';
import BaseButton from '../components/BaseButton';
import FormField from '../components/FormField';
import { getPageTitle } from '../config';
import { useAppDispatch, useAppSelector } from '../stores/hooks';
import { aiResponse } from '../stores/openAiSlice';
import axios from 'axios';
import BaseIcon from '../components/BaseIcon';
const InsightsPage = () => {
const dispatch = useAppDispatch();
const { isAskingResponse } = useAppSelector((state) => state.openAi);
const [question, setQuestion] = useState('');
const [chatHistory, setChatHistory] = useState<Array<{ role: 'user' | 'assistant' | 'system', content: string, type?: 'text' | 'table', data?: any[] }>>([]);
const [isExecutingSql, setIsExecutingSql] = useState(false);
const extractText = (payload: any) => {
if (!payload || typeof payload !== 'object') return '';
const data = payload.data || payload;
if (Array.isArray(data.output)) {
let combined = '';
for (const item of data.output) {
if (!item || !Array.isArray(item.content)) continue;
for (const block of item.content) {
if (block?.type === 'output_text' && typeof block.text === 'string') {
combined += block.text;
}
}
}
if (combined) return combined;
}
if (data.choices?.[0]?.message?.content) {
return data.choices[0].message.content;
}
return '';
};
const handleAsk = async (e?: React.FormEvent) => {
if (e) e.preventDefault();
if (!question.trim()) return;
const userQuestion = question;
setQuestion('');
setChatHistory(prev => [...prev, { role: 'user', content: userQuestion }]);
try {
// Step 1: Generate SQL
const systemPrompt = `You are a sports data assistant. You have access to a PostgreSQL database with:
- players: id, name, position, teamId
- player_stats: id, playerId, game_date, points, three_pointers_made, three_point_attempts, rebounds, assists, minutes
- betting_lines: id, line_name, event_date, spread, moneyline_home, moneyline_away, total
Translate the user question to a single SELECT SQL statement.
Use window functions for 'last N games' (e.g. ROW_NUMBER() OVER (PARTITION BY ps.playerId ORDER BY ps.game_date DESC)).
Return ONLY a JSON object: { "sql": "SELECT ..." }.`;
const aiGenSqlResp = await dispatch(aiResponse({
input: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userQuestion }
]
})).unwrap();
const aiText = extractText(aiGenSqlResp);
let sql = '';
try {
const cleanText = aiText.replace(/```json|```/g, '').trim();
const parsed = JSON.parse(cleanText);
sql = parsed.sql;
} catch (err) {
const match = aiText.match(/SELECT[\s\S]+/i);
if (match) sql = match[0];
}
if (!sql) {
setChatHistory(prev => [...prev, { role: 'assistant', content: "I couldn't generate a valid query for that question. Could you try rephrasing it?" }]);
return;
}
// Step 2: Execute SQL
setIsExecutingSql(true);
const sqlResult = await axios.post('/sql', { sql });
setIsExecutingSql(false);
const rows = sqlResult.data.rows;
if (!rows || rows.length === 0) {
setChatHistory(prev => [...prev, { role: 'assistant', content: "I found no data matching your query." }]);
return;
}
// Step 3: Summarize Results
const summaryPrompt = `Based on the following data from the database, answer the user's question: "${userQuestion}"
Data: ${JSON.stringify(rows.slice(0, 10))}
Provide a concise, professional summary. Mention specific names and numbers.`;
const aiSummaryResp = await dispatch(aiResponse({
input: [
{ role: 'system', content: 'You are a sports analyst.' },
{ role: 'user', content: summaryPrompt }
]
})).unwrap();
const summary = extractText(aiSummaryResp);
setChatHistory(prev => [...prev, {
role: 'assistant',
content: summary,
type: 'table',
data: rows
}]);
} catch (error) {
console.error(error);
setIsExecutingSql(false);
setChatHistory(prev => [...prev, { role: 'assistant', content: "Sorry, I encountered an error while processing your request." }]);
}
};
return (
<>
<Head>
<title>{getPageTitle('AI Sports Insights')}</title>
</Head>
<SectionMain>
<SectionTitleLineWithButton icon={icon.mdiRobot} title="AI Sports Insights" main>
<BaseButton
label="Clear Chat"
color="whiteDark"
icon={icon.mdiDelete}
onClick={() => setChatHistory([])}
/>
</SectionTitleLineWithButton>
<CardBox className="mb-6">
<div className="flex flex-col space-y-4 min-h-[400px] max-h-[600px] overflow-y-auto p-4 bg-gray-50 dark:bg-dark-800 rounded-lg border border-gray-200 dark:border-dark-700">
{chatHistory.length === 0 && (
<div className="flex flex-col items-center justify-center h-full text-gray-400 space-y-2">
<BaseIcon path={icon.mdiCommentQuestion} size={48} />
<p>Ask me anything about NBA, NFL, or NHL stats!</p>
<p className="text-xs">Example: &quot;Who are the top 5 scorers in their last 10 games?&quot;</p>
</div>
)}
{chatHistory.map((msg, i) => (
<div key={i} className={`flex ${msg.role === 'user' ? 'justify-end' : 'justify-start'}`}>
<div className={`max-w-[80%] p-3 rounded-2xl ${
msg.role === 'user'
? 'bg-blue-600 text-white rounded-tr-none'
: 'bg-white dark:bg-dark-900 border border-gray-200 dark:border-dark-700 rounded-tl-none'
} shadow-sm`}>
<p className="whitespace-pre-wrap text-sm">{msg.content}</p>
{msg.type === 'table' && msg.data && (
<div className="mt-4 overflow-x-auto border-t pt-2 border-gray-100 dark:border-dark-700">
<table className="min-w-full text-xs">
<thead>
<tr>
{Object.keys(msg.data[0] || {}).map(k => (
<th key={k} className="text-left py-1 px-2 font-bold uppercase">{k}</th>
))}
</tr>
</thead>
<tbody>
{msg.data.slice(0, 5).map((row, ri) => (
<tr key={ri} className="border-t border-gray-50 dark:border-dark-800">
{Object.values(row).map((v: any, vi) => (
<td key={vi} className="py-1 px-2">{String(v)}</td>
))}
</tr>
))}
</tbody>
</table>
{msg.data.length > 5 && <p className="text-[10px] text-gray-400 mt-1 italic">Showing 5 of {msg.data.length} results</p>}
</div>
)}
</div>
</div>
))}
{(isAskingResponse || isExecutingSql) && (
<div className="flex justify-start">
<div className="bg-white dark:bg-dark-900 border border-gray-200 dark:border-dark-700 p-3 rounded-2xl rounded-tl-none shadow-sm flex items-center space-x-2">
<div className="w-2 h-2 bg-blue-500 rounded-full animate-bounce" style={{ animationDelay: '0ms' }} />
<div className="w-2 h-2 bg-blue-500 rounded-full animate-bounce" style={{ animationDelay: '150ms' }} />
<div className="w-2 h-2 bg-blue-500 rounded-full animate-bounce" style={{ animationDelay: '300ms' }} />
</div>
</div>
)}
</div>
<form onSubmit={handleAsk} className="mt-4 flex space-x-2">
<FormField className="flex-grow mb-0">
<input
value={question}
onChange={e => setQuestion(e.target.value)}
placeholder="e.g. &quot;Show me players with 70% 3PT accuracy in last 15 games&quot;"
className="w-full"
disabled={isAskingResponse || isExecutingSql}
/>
</FormField>
<BaseButton
type="submit"
color="info"
icon={icon.mdiSend}
disabled={isAskingResponse || isExecutingSql || !question.trim()}
/>
</form>
</CardBox>
</SectionMain>
</>
);
};
InsightsPage.getLayout = function getLayout(page: ReactElement) {
return <LayoutAuthenticated>{page}</LayoutAuthenticated>;
};
export default InsightsPage;