Skip to content

Commit 458f432

Browse files
authored
Merge pull request #122 from Agbasimere/main
feat(#102): Advanced analytics and reporting dashboard
2 parents 1131fe8 + 2315590 commit 458f432

24 files changed

+1861
-13
lines changed

.github/workflows/docs-validation.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ jobs:
1414

1515
- name: Install Rust
1616
uses: dtolnay/rust-toolchain@stable
17+
with:
18+
components: rustfmt
19+
targets: wasm32-unknown-unknown
20+
21+
- name: Cache cargo
22+
uses: Swatinem/rust-cache@v2
1723

1824
# 1. Link checking system (Temporarily disabled)
1925
# - name: Lychee Link Checker
@@ -22,6 +28,10 @@ jobs:
2228
# args: --config lychee.toml "./**/*.md"
2329
# fail: true
2430

25-
# 2. Validate code examples (This stays!)
26-
- name: Verify Code Snippets
27-
run: cargo test --doc
31+
# 2. Validate code examples (per workspace member)
32+
- name: Verify Code Snippets (teachlink)
33+
run: cargo test --doc -p teachlink-contract
34+
- name: Verify Code Snippets (governance)
35+
run: cargo test --doc -p governance-contract
36+
- name: Verify Code Snippets (insurance)
37+
run: cargo test --doc -p enhanced-insurance

contracts/teachlink/src/events.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,42 @@ pub struct MetadataUpdatedEvent {
415415
pub owner: Address,
416416
pub timestamp: u64,
417417
}
418+
419+
// ================= Advanced Analytics & Reporting Events =================
420+
421+
#[contractevent]
422+
#[derive(Clone, Debug)]
423+
pub struct ReportGeneratedEvent {
424+
pub report_id: u64,
425+
pub report_type: crate::types::ReportType,
426+
pub generated_by: Address,
427+
pub period_start: u64,
428+
pub period_end: u64,
429+
}
430+
431+
#[contractevent]
432+
#[derive(Clone, Debug)]
433+
pub struct ReportScheduledEvent {
434+
pub schedule_id: u64,
435+
pub template_id: u64,
436+
pub owner: Address,
437+
pub next_run_at: u64,
438+
}
439+
440+
#[contractevent]
441+
#[derive(Clone, Debug)]
442+
pub struct ReportCommentAddedEvent {
443+
pub report_id: u64,
444+
pub comment_id: u64,
445+
pub author: Address,
446+
}
447+
448+
#[contractevent]
449+
#[derive(Clone, Debug)]
450+
pub struct AlertTriggeredEvent {
451+
pub rule_id: u64,
452+
pub condition_type: crate::types::AlertConditionType,
453+
pub current_value: i128,
454+
pub threshold: i128,
455+
pub triggered_at: u64,
456+
}

contracts/teachlink/src/lib.rs

Lines changed: 121 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
//! | [`audit`] | Audit trail and compliance reporting |
4141
//! | [`atomic_swap`] | Cross-chain atomic swaps |
4242
//! | [`analytics`] | Bridge monitoring and analytics |
43+
//! | [`reporting`] | Advanced analytics, report templates, dashboards, and alerting |
4344
//! | [`rewards`] | Reward pool management and distribution |
4445
//! | [`escrow`] | Multi-signature escrow with dispute resolution |
4546
//! | [`tokenization`] | Educational content NFT minting and management |
@@ -107,6 +108,7 @@ mod notification;
107108
mod notification_events_basic;
108109
// mod notification_tests; // TODO: Re-enable when testutils dependencies are resolved
109110
mod notification_types;
111+
mod reporting;
110112
mod rewards;
111113
mod slashing;
112114
// mod social_events;
@@ -118,15 +120,17 @@ pub mod validation;
118120

119121
pub use errors::{BridgeError, EscrowError, RewardsError};
120122
pub use types::{
121-
ArbitratorProfile, AtomicSwap, AuditRecord, BridgeMetrics, BridgeProposal, BridgeTransaction,
122-
ChainConfig, ChainMetrics, ComplianceReport, ConsensusState, ContentMetadata, ContentToken,
123-
ContentTokenParameters, CrossChainMessage, CrossChainPacket, DisputeOutcome, EmergencyState,
124-
Escrow, EscrowMetrics, EscrowParameters, EscrowStatus, LiquidityPool, MultiChainAsset,
125-
NotificationChannel, NotificationContent, NotificationPreference, NotificationSchedule,
126-
NotificationTemplate, NotificationTracking, OperationType, PacketStatus, ProposalStatus,
127-
ProvenanceRecord, RewardRate, RewardType, SlashingReason, SlashingRecord, SwapStatus,
128-
TransferType, UserNotificationSettings, UserReputation, UserReward, ValidatorInfo,
129-
ValidatorReward, ValidatorSignature,
123+
AlertConditionType, AlertRule, ArbitratorProfile, AtomicSwap, AuditRecord, BridgeMetrics,
124+
BridgeProposal, BridgeTransaction, ChainConfig, ChainMetrics, ComplianceReport, ConsensusState,
125+
ContentMetadata, ContentToken, ContentTokenParameters, CrossChainMessage, CrossChainPacket,
126+
DashboardAnalytics, DisputeOutcome, EmergencyState, Escrow, EscrowMetrics, EscrowParameters,
127+
EscrowStatus, LiquidityPool, MultiChainAsset, NotificationChannel, NotificationContent,
128+
NotificationPreference, NotificationSchedule, NotificationTemplate, NotificationTracking,
129+
OperationType, PacketStatus, ProposalStatus, ProvenanceRecord, ReportComment, ReportSchedule,
130+
ReportSnapshot, ReportTemplate, ReportType, ReportUsage, RewardRate, RewardType,
131+
SlashingReason, SlashingRecord, SwapStatus, TransferType, UserNotificationSettings,
132+
UserReputation, UserReward, ValidatorInfo, ValidatorReward, ValidatorSignature,
133+
VisualizationDataPoint,
130134
};
131135

132136
/// TeachLink main contract.
@@ -688,6 +692,114 @@ impl TeachLinkBridge {
688692
analytics::AnalyticsManager::get_bridge_statistics(&env)
689693
}
690694
695+
// ========== Advanced Analytics & Reporting Functions ==========
696+
697+
/// Get dashboard-ready aggregate analytics for visualizations
698+
pub fn get_dashboard_analytics(env: Env) -> DashboardAnalytics {
699+
reporting::ReportingManager::get_dashboard_analytics(&env)
700+
}
701+
702+
/// Create a report template
703+
pub fn create_report_template(
704+
env: Env,
705+
creator: Address,
706+
name: Bytes,
707+
report_type: ReportType,
708+
config: Bytes,
709+
) -> Result<u64, BridgeError> {
710+
reporting::ReportingManager::create_report_template(&env, creator, name, report_type, config)
711+
}
712+
713+
/// Get report template by id
714+
pub fn get_report_template(env: Env, template_id: u64) -> Option<ReportTemplate> {
715+
reporting::ReportingManager::get_report_template(&env, template_id)
716+
}
717+
718+
/// Schedule a report
719+
pub fn schedule_report(
720+
env: Env,
721+
owner: Address,
722+
template_id: u64,
723+
next_run_at: u64,
724+
interval_seconds: u64,
725+
) -> Result<u64, BridgeError> {
726+
reporting::ReportingManager::schedule_report(&env, owner, template_id, next_run_at, interval_seconds)
727+
}
728+
729+
/// Get scheduled reports for an owner
730+
pub fn get_scheduled_reports(env: Env, owner: Address) -> Vec<ReportSchedule> {
731+
reporting::ReportingManager::get_scheduled_reports(&env, owner)
732+
}
733+
734+
/// Generate a report snapshot
735+
pub fn generate_report_snapshot(
736+
env: Env,
737+
generator: Address,
738+
template_id: u64,
739+
period_start: u64,
740+
period_end: u64,
741+
) -> Result<u64, BridgeError> {
742+
reporting::ReportingManager::generate_report_snapshot(
743+
&env, generator, template_id, period_start, period_end,
744+
)
745+
}
746+
747+
/// Get report snapshot by id
748+
pub fn get_report_snapshot(env: Env, report_id: u64) -> Option<ReportSnapshot> {
749+
reporting::ReportingManager::get_report_snapshot(&env, report_id)
750+
}
751+
752+
/// Record report view for usage analytics
753+
pub fn record_report_view(env: Env, report_id: u64, viewer: Address) -> Result<(), BridgeError> {
754+
reporting::ReportingManager::record_report_view(&env, report_id, viewer)
755+
}
756+
757+
/// Get report usage count
758+
pub fn get_report_usage_count(env: Env, report_id: u64) -> u32 {
759+
reporting::ReportingManager::get_report_usage_count(&env, report_id)
760+
}
761+
762+
/// Add comment to a report
763+
pub fn add_report_comment(
764+
env: Env,
765+
report_id: u64,
766+
author: Address,
767+
body: Bytes,
768+
) -> Result<u64, BridgeError> {
769+
reporting::ReportingManager::add_report_comment(&env, report_id, author, body)
770+
}
771+
772+
/// Get comments for a report
773+
pub fn get_report_comments(env: Env, report_id: u64) -> Vec<ReportComment> {
774+
reporting::ReportingManager::get_report_comments(&env, report_id)
775+
}
776+
777+
/// Create an alert rule
778+
pub fn create_alert_rule(
779+
env: Env,
780+
owner: Address,
781+
name: Bytes,
782+
condition_type: AlertConditionType,
783+
threshold: i128,
784+
) -> Result<u64, BridgeError> {
785+
reporting::ReportingManager::create_alert_rule(&env, owner, name, condition_type, threshold)
786+
}
787+
788+
/// Get alert rules for an owner
789+
pub fn get_alert_rules(env: Env, owner: Address) -> Vec<AlertRule> {
790+
reporting::ReportingManager::get_alert_rules(&env, owner)
791+
}
792+
793+
/// Evaluate alert rules (returns triggered rule ids)
794+
pub fn evaluate_alerts(env: Env) -> Vec<u64> {
795+
reporting::ReportingManager::evaluate_alerts(&env)
796+
}
797+
798+
/// Get recent report snapshots
799+
pub fn get_recent_report_snapshots(env: Env, limit: u32) -> Vec<ReportSnapshot> {
800+
reporting::ReportingManager::get_recent_report_snapshots(&env, limit)
801+
}
802+
691803
// ========== Rewards Functions ==========
692804
693805
/// Initialize the rewards system

0 commit comments

Comments
 (0)