bugfixing search for sector, country, analystRating
This commit is contained in:
parent
93f2d10e13
commit
05bc36f56e
@ -90,7 +90,6 @@ const allRules = {
|
|||||||
var: { label: 'Value-at-Risk', step: ['-1%','-5%','-10%','-15%','-20%'], category: 'fund', defaultCondition: 'over', defaultValue: '1%' },
|
var: { label: 'Value-at-Risk', step: ['-1%','-5%','-10%','-15%','-20%'], category: 'fund', defaultCondition: 'over', defaultValue: '1%' },
|
||||||
trendAnalysis: { label: 'AI Trend Analysis (Bullish)', step: ['80%','70%','60%','50%'], category: 'ai', defaultCondition: 'over', defaultValue: '50%' },
|
trendAnalysis: { label: 'AI Trend Analysis (Bullish)', step: ['80%','70%','60%','50%'], category: 'ai', defaultCondition: 'over', defaultValue: '50%' },
|
||||||
fundamentalAnalysis: { label: 'AI Fundamental Analysis (Bullish)', step: ['80%','70%','60%','50%'], category: 'ai', defaultCondition: 'over', defaultValue: '50%' },
|
fundamentalAnalysis: { label: 'AI Fundamental Analysis (Bullish)', step: ['80%','70%','60%','50%'], category: 'ai', defaultCondition: 'over', defaultValue: '50%' },
|
||||||
analystRating: { label: 'Analyst Rating', step: ['Buy', 'Hold', 'Sell'], category: 'fund', defaultCondition: '', defaultValue: 'Buy' },
|
|
||||||
currentRatio: { label: 'Current Ratio', step: [50,40,30,20,10,5,1], category: 'fund', defaultCondition: 'over', defaultValue: 1 },
|
currentRatio: { label: 'Current Ratio', step: [50,40,30,20,10,5,1], category: 'fund', defaultCondition: 'over', defaultValue: 1 },
|
||||||
quickRatio: { label: 'Quick Ratio', step: [50,40,30,20,10,5,1], category: 'fund', defaultCondition: 'over', defaultValue: 1 },
|
quickRatio: { label: 'Quick Ratio', step: [50,40,30,20,10,5,1], category: 'fund', defaultCondition: 'over', defaultValue: 1 },
|
||||||
debtEquityRatio: { label: 'Debt / Equity', step: [50,40,30,20,10,5,1], category: 'fund', defaultCondition: 'over', defaultValue: 1 },
|
debtEquityRatio: { label: 'Debt / Equity', step: [50,40,30,20,10,5,1], category: 'fund', defaultCondition: 'over', defaultValue: 1 },
|
||||||
@ -132,6 +131,7 @@ const allRules = {
|
|||||||
revenuePerEmployee: { label: 'Revenue Per Employee', step: ['5M','3M','2M','1M','500K','100K',0], category: 'fund', defaultCondition: 'over', defaultValue: '0' },
|
revenuePerEmployee: { label: 'Revenue Per Employee', step: ['5M','3M','2M','1M','500K','100K',0], category: 'fund', defaultCondition: 'over', defaultValue: '0' },
|
||||||
profitPerEmployee: { label: 'Profit Per Employee', step: ['5M','3M','2M','1M','500K','100K',0], category: 'fund', defaultCondition: 'over', defaultValue: '0' },
|
profitPerEmployee: { label: 'Profit Per Employee', step: ['5M','3M','2M','1M','500K','100K',0], category: 'fund', defaultCondition: 'over', defaultValue: '0' },
|
||||||
totalLiabilities: { label: 'Total Liabilities', step: ['500B','200B','100B','50B','10B','1B','100M','10M','1M'], category: 'fund', defaultCondition: 'over', defaultValue: '1M' },
|
totalLiabilities: { label: 'Total Liabilities', step: ['500B','200B','100B','50B','10B','1B','100M','10M','1M'], category: 'fund', defaultCondition: 'over', defaultValue: '1M' },
|
||||||
|
analystRating: { label: 'Analyst Rating', step: ['Buy', 'Hold', 'Sell'], category: 'fund', defaultCondition: '', defaultValue: 'any' },
|
||||||
sector: { label: 'Sector', step: sectorList, category: 'fund', defaultCondition: '', defaultValue: 'any' },
|
sector: { label: 'Sector', step: sectorList, category: 'fund', defaultCondition: '', defaultValue: 'any' },
|
||||||
country: { label: 'Country', step: listOfRelevantCountries, category: 'fund', defaultCondition: '', defaultValue: 'any' },
|
country: { label: 'Country', step: listOfRelevantCountries, category: 'fund', defaultCondition: '', defaultValue: 'any' },
|
||||||
|
|
||||||
@ -243,8 +243,6 @@ function handleAddRule() {
|
|||||||
switch (ruleName) {
|
switch (ruleName) {
|
||||||
case 'analystRating':
|
case 'analystRating':
|
||||||
case 'sector':
|
case 'sector':
|
||||||
newRule = { name: ruleName, value: valueMappings[ruleName] };
|
|
||||||
break;
|
|
||||||
case 'country':
|
case 'country':
|
||||||
newRule = { name: ruleName, value: Array.isArray(valueMappings[ruleName]) ? valueMappings[ruleName] : [valueMappings[ruleName]] }; // Ensure value is an array
|
newRule = { name: ruleName, value: Array.isArray(valueMappings[ruleName]) ? valueMappings[ruleName] : [valueMappings[ruleName]] }; // Ensure value is an array
|
||||||
break;
|
break;
|
||||||
@ -503,8 +501,9 @@ function changeRuleCondition(name: string, state: string) {
|
|||||||
|
|
||||||
async function handleChangeValue(value) {
|
async function handleChangeValue(value) {
|
||||||
// Check if the current rule is "country"
|
// Check if the current rule is "country"
|
||||||
if (ruleName === "country") {
|
if (['analystRating','sector','country']?.includes(ruleName)) {
|
||||||
// Ensure valueMappings[ruleName] is initialized as an array
|
// Ensure valueMappings[ruleName] is initialized as an array
|
||||||
|
searchQuery = '';
|
||||||
if (!Array.isArray(valueMappings[ruleName])) {
|
if (!Array.isArray(valueMappings[ruleName])) {
|
||||||
valueMappings[ruleName] = []; // Initialize as an empty array if not already
|
valueMappings[ruleName] = []; // Initialize as an empty array if not already
|
||||||
}
|
}
|
||||||
@ -626,13 +625,14 @@ function handleInput(event) {
|
|||||||
testList = [];
|
testList = [];
|
||||||
|
|
||||||
if (searchQuery.length > 0) {
|
if (searchQuery.length > 0) {
|
||||||
testList = listOfRelevantCountries?.filter(item => {
|
|
||||||
const country = item?.toLowerCase();
|
const rawList = ruleName === 'country' ? listOfRelevantCountries : ruleName === 'sector' ? sectorList : ['Buy','Hold','Sell'];
|
||||||
|
testList = rawList?.filter(item => {
|
||||||
|
const index = item?.toLowerCase();
|
||||||
// Check if country starts with searchQuery
|
// Check if country starts with searchQuery
|
||||||
return country.startsWith(searchQuery);
|
return index?.startsWith(searchQuery);
|
||||||
}) || [];
|
}) || [];
|
||||||
}
|
}
|
||||||
console.log(testList);
|
|
||||||
}, 50);
|
}, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -857,7 +857,7 @@ function handleInput(event) {
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<DropdownMenu.Group class="min-h-10 mt-2">
|
<DropdownMenu.Group class="min-h-10 mt-2">
|
||||||
{#if row?.rule !== 'country'}
|
{#if !['analystRating','sector','country']?.includes(row?.rule)}
|
||||||
{#each row?.step as newValue}
|
{#each row?.step as newValue}
|
||||||
<DropdownMenu.Item class="sm:hover:bg-[#27272A]">
|
<DropdownMenu.Item class="sm:hover:bg-[#27272A]">
|
||||||
|
|
||||||
@ -868,16 +868,16 @@ function handleInput(event) {
|
|||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
{#each (testList.length > 0 && searchQuery?.length > 0 ? testList : searchQuery?.length > 0 && testList?.length === 0 ? [] : listOfRelevantCountries) as item}
|
{#each (testList.length > 0 && searchQuery?.length > 0 ? testList : searchQuery?.length > 0 && testList?.length === 0 ? [] : (row?.rule === 'country' ? listOfRelevantCountries : row?.rule === 'sector' ? sectorList : ['Buy','Hold','Sell'])) as item}
|
||||||
<DropdownMenu.Item class="sm:hover:bg-[#27272A]">
|
<DropdownMenu.Item class="sm:hover:bg-[#27272A]">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<label on:click={() => {handleChangeValue(item)}} class="cursor-pointer text-white" for={item}>
|
<label on:click={() => {handleChangeValue(item)}} class="cursor-pointer text-white" for={item}>
|
||||||
<input type="checkbox" checked={ruleOfList?.some(rule =>
|
<input type="checkbox" checked={ruleOfList?.some(rule =>
|
||||||
rule?.name === 'country' &&
|
rule?.name === row?.rule &&
|
||||||
Array?.isArray(rule?.value) &&
|
Array?.isArray(rule?.value) &&
|
||||||
rule?.value.includes(item))}
|
rule?.value.includes(item))}
|
||||||
class="h-4 w-4 rounded bg-dark-500 border border-gray-500 text-blue-600 focus:ring-blue-500" id={ruleOfList?.some(rule =>
|
class="h-4 w-4 rounded bg-dark-500 border border-gray-500 text-blue-600 focus:ring-blue-500" id={ruleOfList?.some(rule =>
|
||||||
rule?.name === 'country' &&
|
rule?.name === row?.rule &&
|
||||||
Array?.isArray(rule?.value) &&
|
Array?.isArray(rule?.value) &&
|
||||||
rule?.value.includes(item))}>
|
rule?.value.includes(item))}>
|
||||||
<span class="ml-2">{item}</span>
|
<span class="ml-2">{item}</span>
|
||||||
|
|||||||
@ -83,19 +83,13 @@ async function filterStockScreenerData(stockScreenerData, ruleOfList) {
|
|||||||
} else if (rule.condition === "under" && accuracy > ruleValue) {
|
} else if (rule.condition === "under" && accuracy > ruleValue) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (rule.name === "analystRating") {
|
} else if (["analystRating", "sector", "country"].includes(rule.name)) {
|
||||||
if (
|
if (rule.value === "any") {
|
||||||
["Buy", "Hold", "Sell"]?.includes(rule.value) &&
|
// Skip filtering if the value is "any"
|
||||||
itemValue !== rule.value
|
continue;
|
||||||
) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else if (rule.name === "sector") {
|
|
||||||
if (sectorList?.includes(rule.value) && itemValue !== rule.value) {
|
// Handle the case where rule.value can be a list of items
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (rule.name === "country") {
|
|
||||||
// Handle the case where rule.value can be a list of countries
|
|
||||||
if (Array.isArray(ruleValue) && !ruleValue.includes(itemValue)) {
|
if (Array.isArray(ruleValue) && !ruleValue.includes(itemValue)) {
|
||||||
return false;
|
return false;
|
||||||
} else if (!Array.isArray(ruleValue) && itemValue !== ruleValue) {
|
} else if (!Array.isArray(ruleValue) && itemValue !== ruleValue) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user