Skip to main content
The Logic module contains core business logic for Estudo Organizado, including timer management, revision scheduling, performance analytics, and automated study planning.

Timer Functions

isTimerActive

Check if a timer is currently running.
import { isTimerActive } from './logic.js';

if (isTimerActive('crono_livre')) {
  console.log('Free timer is running');
}
eventId
string
required
Event ID or 'crono_livre' for the free timer
return
boolean
true if timer is active, false otherwise

getElapsedSeconds

Calculate total elapsed time for an event in seconds.
import { getElapsedSeconds } from './logic.js';

const evento = state.eventos[0];
const elapsed = getElapsedSeconds(evento);
console.log(`Studied for ${elapsed} seconds`);
ev
object
required
Event object with tempoAcumulado and optional _timerStart
return
number
Total elapsed seconds (accumulated + current session if running)

toggleTimer

Start or pause a timer.
import { toggleTimer } from './logic.js';

toggleTimer('ev_abc123'); // Starts or pauses timer for event
eventId
string
required
Event ID or 'crono_livre'
When starting:
  • Sets _timerStart to current timestamp
  • Calls reattachTimers() to start interval
  • Dispatches app:refreshEventCard event
When pausing:
  • Accumulates elapsed time into tempoAcumulado
  • Removes _timerStart
  • Clears interval
All timer state changes automatically trigger scheduleSave().

toggleTimerMode

Toggle between continuous and Pomodoro timer modes.
import { toggleTimerMode } from './logic.js';

toggleTimerMode(); // Switches mode
In Pomodoro mode:
  • Timer auto-pauses after focus period (default 25 min)
  • Plays alarm sound
  • Shows desktop notification if permitted
  • Dispatches toast with break reminder

reattachTimers

Reattach interval updates for all active timers.
import { reattachTimers } from './logic.js';

reattachTimers(); // Called after state changes
This function:
  • Clears all existing intervals
  • Finds all events with _timerStart
  • Creates new intervals that update UI every second
  • Implements Pomodoro auto-pause logic

addTimerMinutes

Add extra time to an event’s target duration.
import { addTimerMinutes } from './logic.js';

addTimerMinutes('ev_abc123', 15); // Add 15 minutes
eventId
string
required
Event ID or 'crono_livre'
minutes
number
required
Minutes to add to the duration

discardTimer

Discard a timer session (resets accumulated time to zero).
import { discardTimer } from './logic.js';

discardTimer('ev_abc123'); // Shows confirmation dialog
eventId
string
required
Event ID or 'crono_livre'
This action requires user confirmation via app:showConfirm event.

marcarEstudei

Mark an event as studied (complete the session).
import { marcarEstudei } from './logic.js';

marcarEstudei('ev_abc123'); // Opens session registration modal
eventId
string
required
Event ID to mark as studied
This function:
  • Opens the session registration modal (if available)
  • Falls back to _marcarEstudeiDirect() if modal not loaded
  • Stops timer and accumulates time
  • Updates event status to 'estudei'
  • Marks associated topic as completed if applicable

deleteEvento

Delete an event permanently.
import { deleteEvento } from './logic.js';

deleteEvento('ev_abc123'); // Shows confirmation dialog
eventId
string
required
Event ID to delete

totalStudySeconds

Calculate total study time in seconds.
import { totalStudySeconds } from './logic.js';

const last7Days = totalStudySeconds(7);
const allTime = totalStudySeconds();
days
number
Optional number of days to look back (null for all time)
return
number
Total seconds studied across matching events

Revision Functions

calcRevisionDates

Calculate scheduled revision dates based on spaced repetition.
import { calcRevisionDates } from './logic.js';

const dates = calcRevisionDates('2026-03-01', [0, 1], 0);
// Returns: ['2026-03-02', '2026-03-08', '2026-03-31', '2026-05-30']
// Based on default frequency: [1, 7, 30, 90] days
dataConclusao
string
required
Completion date in ‘YYYY-MM-DD’ format
feitas
array
required
Array of completed revision indices
adiamentos
number
default:0
Number of days to postpone the schedule
return
array
Array of date strings for remaining revisions
Results are cached using a Map for performance. Call invalidateRevCache() when frequency settings change.

getPendingRevisoes

Get all revisions due today or earlier.
import { getPendingRevisoes } from './logic.js';

const pending = getPendingRevisoes();
pending.forEach(rev => {
  console.log(rev.assunto.nome, 'due on', rev.data);
});
return
array
Array of revision objects with:
  • assunto: Topic object
  • disc: Discipline object
  • edital: Exam notice object
  • data: Due date string
Results are cached. Call invalidatePendingRevCache() after marking revisions complete.

invalidateRevCache

Clear the revision dates cache.
import { invalidateRevCache } from './logic.js';

state.config.frequenciaRevisao = [1, 3, 7, 15, 30];
invalidateRevCache();

invalidatePendingRevCache

Clear the pending revisions cache.
import { invalidatePendingRevCache } from './logic.js';

assunto.revisoesFetas.push(1);
invalidatePendingRevCache();

Discipline Functions

getAllDisciplinas

Get all disciplines from all exam notices with parent context.
import { getAllDisciplinas } from './logic.js';

const allDiscs = getAllDisciplinas();
allDiscs.forEach(({ disc, edital }) => {
  console.log(disc.nome, 'from', edital.titulo);
});
return
array
Array of objects with disc and edital properties
Results are cached. Call invalidateDiscCache() when editais change.

getDisc

Get a discipline by ID with parent context.
import { getDisc } from './logic.js';

const { disc, edital } = getDisc('disc_abc123');
console.log(disc.nome, disc.icone);
id
string
required
Discipline ID
return
object|null
Object with disc and edital properties, or null if not found

invalidateDiscCache

Clear the disciplines cache.
import { invalidateDiscCache } from './logic.js';

state.editais.push(newEdital);
invalidateDiscCache();

Analytics Functions

getPerformanceStats

Get question performance statistics.
import { getPerformanceStats } from './logic.js';

const { questionsTotal, questionsCorrect, questionsWrong } = getPerformanceStats();
const accuracy = (questionsCorrect / questionsTotal) * 100;
return
object
Object with:
  • questionsTotal: number
  • questionsCorrect: number
  • questionsWrong: number

getPagesReadStats

Get total pages read across all study sessions.
import { getPagesReadStats } from './logic.js';

const totalPages = getPagesReadStats();
return
number
Total pages read

getSyllabusProgress

Get completion progress for course lessons.
import { getSyllabusProgress } from './logic.js';

const { totalAssuntos, totalConcluidos } = getSyllabusProgress();
const progress = (totalConcluidos / totalAssuntos) * 100;
return
object
Object with:
  • totalAssuntos: Total number of lessons
  • totalConcluidos: Number of completed lessons

getConsistencyStreak

Calculate study consistency and generate heatmap.
import { getConsistencyStreak } from './logic.js';

const { currentStreak, maxStreak, heatmap } = getConsistencyStreak();
console.log(`Current streak: ${currentStreak} days`);
console.log(`Best streak: ${maxStreak} days`);
return
object
Object with:
  • currentStreak: number - Consecutive days studied up to today
  • maxStreak: number - Longest historical streak
  • heatmap: array - Boolean array of last 30 days (true = studied)

getSubjectStats

Get per-discipline study statistics.
import { getSubjectStats } from './logic.js';

const stats = getSubjectStats();
stats.forEach(s => {
  console.log(s.nome, '-', s.tempo, 'seconds', s.acertos, 'correct');
});
return
array
Array of objects with:
  • id: string
  • nome: string
  • tempo: number - Total seconds studied
  • acertos: number - Correct answers
  • erros: number - Wrong answers

getCurrentWeekStats

Get current week study statistics.
import { getCurrentWeekStats } from './logic.js';

const {
  startStr,
  endStr,
  totalSeconds,
  totalQuestions,
  dailySeconds
} = getCurrentWeekStats();
return
object
Object with:
  • startStr: string - Week start date
  • endStr: string - Week end date
  • totalSeconds: number - Total study time this week
  • totalQuestions: number - Total questions this week
  • dailySeconds: array - Study time per day (7 elements)

getPredictiveStats

Get predictive analytics and weekly goal tracking.
import { getPredictiveStats } from './logic.js';

const {
  status,
  projectedPerc,
  suggestion,
  projectedSeconds,
  targetSeconds
} = getPredictiveStats(40); // 40 hours weekly goal
metaHoras
number
required
Weekly study goal in hours
return
object
Object with:
  • status: string - ‘verde’, ‘amarelo’, or ‘vermelho’
  • projectedPerc: number - Projected percentage of goal
  • suggestion: string - Actionable recommendation
  • projectedSeconds: number - Projected total by week end
  • targetSeconds: number - Target seconds from goal
  • burnRate: number - Current seconds per day rate
  • daysRemaining: number - Days left in week

Planning Functions

calculateRelevanceWeights

Calculate study time distribution based on importance and knowledge.
import { calculateRelevanceWeights } from './logic.js';

const draft = {
  'disc_1': { importancia: 5, conhecimento: 1 },
  'disc_2': { importancia: 3, conhecimento: 4 }
};

const weights = calculateRelevanceWeights(draft);
// Returns:
// {
//   'disc_1': { importancia: 5, conhecimento: 1, peso: 25, percentual: 71.4 },
//   'disc_2': { importancia: 3, conhecimento: 4, peso: 10, percentual: 28.6 }
// }
relevanciaDraft
object
required
Object mapping discipline IDs to {importancia, conhecimento} ratings (1-5 scale)
return
object
Object mapping discipline IDs to calculated weights with percentual property
Formula: peso = importancia × (6 - conhecimento). Lower knowledge increases weight.

generatePlanejamento

Generate automated study plan from wizard configuration.
import { generatePlanejamento } from './logic.js';

const draft = {
  tipo: 'ciclo',
  disciplinas: ['disc_1', 'disc_2'],
  relevancia: { 'disc_1': { importancia: 5, conhecimento: 2 } },
  horarios: { horasSemanais: 40, sessaoMin: 30, sessaoMax: 120 }
};

const plan = generatePlanejamento(draft);
draft
object
required
Planning configuration with tipo, disciplinas, relevancia, and horarios
return
object
Complete planning object with generated sequencia array
The function:
  • Calculates relevance weights
  • Distributes weekly hours proportionally
  • Breaks sessions into min/max durations
  • Creates sequenced study blocks
  • Saves to state.planejamento
  • Calls syncCicloToEventos() to generate events

deletePlanejamento

Delete the current study plan.
import { deletePlanejamento } from './logic.js';

deletePlanejamento(); // Shows confirmation dialog

iniciarEtapaPlanejamento

Start a study session for a planning sequence item.
import { iniciarEtapaPlanejamento } from './logic.js';

iniciarEtapaPlanejamento('seq_abc123');
seqId
string
required
Sequence item ID from state.planejamento.sequencia
This function:
  • Creates an event for the sequence item
  • Starts the timer automatically
  • Navigates to the timer view

syncCicloToEventos

Generate future events from the planning sequence.
import { syncCicloToEventos } from './logic.js';

syncCicloToEventos(); // Regenerates next 14 days of events
This function:
  • Removes auto-generated future events
  • Keeps events with study time or status=‘estudei’
  • Generates events for next 14 days based on sequence
  • Respects materiasPorDia configuration
  • Honors weekly schedule if tipo=‘semanal’
Call this after modifying planning configuration or sequence order.

Build docs developers (and LLMs) love