-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insight Section for Spam2 #8289
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f9abde8
insights for spam2
keshavsethi 6d620b3
ui changes and refactoring
keshavsethi a5ee023
refactoring
keshavsethi e2eda9e
tests for spam2
keshavsethi 8138fb3
ui update and bug fixes
keshavsethi b2e67fd
Merge branch 'main' into insights
keshavsethi d91665d
minor bug fixes
keshavsethi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
<div class="card-deck w-100 mb-3" id="stats_spam"> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<h5 class="card-title text-secondary font-weight-bold"> <i class="fa fa-circle text-primary"></i> Unmoderated</h5> | ||
<ul class="list-group list-group-flush text-secondary "> | ||
<li class="list-group-item"><%= Node.where(status: 4, created: (Time.now - 1.month)..Time.now).size%> Nodes</li> | ||
<li class="list-group-item"><%= Comment.where(status: 4, timestamp: (Time.now - 1.month)..Time.now).size %> Comments</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<h5 class="card-title text-secondary font-weight-bold"> <i class="fa fa-ban text-danger"></i> Spammed</h5> | ||
<ul class="list-group list-group-flush text-secondary "> | ||
<li class="list-group-item"><%= Node.where(status: 0, created: (Time.now - 1.month)..Time.now).size%> Nodes</li> | ||
<li class="list-group-item"><%= Comment.where(status: 0, timestamp: (Time.now - 1.month)..Time.now).size %> Comments</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<h5 class="card-title text-secondary font-weight-bold"> <i class="fa fa-flag text-warning"></i> Flagged</h5> | ||
<ul class="list-group list-group-flush text-secondary "> | ||
<li class="list-group-item"><%= Node.where('flag > ?', 0).where(created: (Time.now - 1.month)..Time.now).size%> Nodes</li> | ||
<li class="list-group-item"><%= Comment.where('flag > ?', 0).where(timestamp: (Time.now - 1.month)..Time.now).size %> Comments</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<h5 class="card-title text-secondary font-weight-bold"> <i class="fa fa-check text-success"></i> Published</h5> | ||
<ul class="list-group list-group-flush text-secondary "> | ||
<li class="list-group-item"><%= Node.where(status: 1, created: (Time.now - 1.month)..Time.now).size%> Nodes</li> | ||
<li class="list-group-item"><%= Comment.where(status: 1, timestamp: (Time.now - 1.month)..Time.now).count %> Comments</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
<p class="text-secondary">* The above stats are for past month</p> | ||
<div class="card w-100 mt-2 border-0"> | ||
<div class="card-body"> | ||
<h4 class="card-title my-3 text-secondary font-weight-bold"> <i class="fa fa-line-chart text-primary"></i> Moderation graph</h4> | ||
<div id="timeline_spam" class="mt-5 w-100"></div> | ||
</div> | ||
</div> | ||
<div class="card-deck w-100 mt-5"> | ||
<div class="card border-0"> | ||
<div class="card-body"> | ||
<h5 class="card-title text-secondary font-weight-bold"> <i class="fa fa-tags text-primary"></i> Tags followed by moderators and admins</h5> | ||
<% if @popular_tags.present? %> | ||
<div id="moderator_tag"> </div> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="card border-0"> | ||
<div class="card-body"> | ||
<% @moderator_tag.each do |tag|%> | ||
<a class="ml-3 my-2 btn btn-sm light border border-curve"><%= tag.first()%> <span class="badge badge-pill badge-info" data-toggle="tooltip" data-placement="top" title="Moderators and admins following this tag"><%= Tag.followers(tag.first()).where('rusers.role = ?', 'moderator').or(Tag.followers(tag.first()).where('rusers.role = ?', 'admin')).size %></span></a> | ||
<%end%> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script> | ||
<script> | ||
var options = { | ||
chart: { | ||
type: "line", | ||
height: 300, | ||
foreColor: "#999", | ||
scroller: { | ||
enabled: true, | ||
track: { | ||
height: 7, | ||
background: '#e0e0e0' | ||
}, | ||
thumb: { | ||
height: 10, | ||
background: '#94E3FF' | ||
}, | ||
scrollButtons: { | ||
enabled: true, | ||
size: 9, | ||
borderWidth: 2, | ||
borderColor: '#008FFB', | ||
fillColor: '#008FFB' | ||
}, | ||
padding: { | ||
left: 30, | ||
right: 20 | ||
} | ||
} | ||
}, | ||
colors: ['#E8D020', '#E85C20', '#165F8B'], | ||
stroke: { | ||
curve: "smooth", | ||
width: 3 | ||
}, | ||
dataLabels: { | ||
enabled: false | ||
}, | ||
series: [{ | ||
name: 'Flagged Nodes', | ||
data: generateWeekWiseTimeSeries(0) | ||
}, { | ||
name: 'Spammed Nodes', | ||
data: generateWeekWiseTimeSeries(1) | ||
}, { | ||
name: 'Unmoderated Nodes', | ||
data: generateWeekWiseTimeSeries(2) | ||
}], | ||
markers: { | ||
size: 0, | ||
strokeColor: "#fff", | ||
strokeWidth: 3, | ||
strokeOpacity: 1, | ||
fillOpacity: 1, | ||
hover: { | ||
size: 6 | ||
} | ||
}, | ||
xaxis: { | ||
type: "datetime", | ||
axisBorder: { | ||
show: false | ||
}, | ||
axisTicks: { | ||
show: false | ||
} | ||
}, | ||
yaxis: { | ||
tickAmount: 6, | ||
min: 0, | ||
opposite: true, | ||
labels: { | ||
offsetX: 24, | ||
offsetY: -5 | ||
}, | ||
tooltip: { | ||
enabled: true | ||
} | ||
}, | ||
grid: { | ||
padding: { | ||
left: -5, | ||
right: 5 | ||
} | ||
}, | ||
tooltip: { | ||
x: { | ||
format: "dd MMM yyyy" | ||
}, | ||
}, | ||
legend: { | ||
position: 'top', | ||
horizontalAlign: 'left' | ||
} | ||
}; | ||
var chart = new ApexCharts(document.querySelector("#timeline_spam"), options); | ||
chart.render(); | ||
|
||
function generateWeekWiseTimeSeries(s) { | ||
var values = [ | ||
<%= @graph_flagged.values if @graph_flagged.present? %>, | ||
<%= @graph_spammed.values if @graph_spammed.present? %>, | ||
<%= @graph_unmoderated.values if @graph_unmoderated.present? %> | ||
]; | ||
var i = 0; | ||
var months_dates = <%= @graph_spammed.keys if @graph_spammed.present? %>; | ||
var count = months_dates.length; | ||
var months = months_dates.map(x => new Date(x).getTime()); | ||
var series = []; | ||
while (i < count) { | ||
for (var j = 0; j < months.length; j++) { | ||
series.push([months[j], values[s][i]]); | ||
i++; | ||
} | ||
} | ||
return series; | ||
} | ||
var values = <%= @popular_tags.values if @popular_tags.present? %>; | ||
var data = <%= raw (@popular_tags.keys) if @popular_tags.present? %>; | ||
var page; | ||
var options = { | ||
chart: { | ||
height: 500, | ||
type: 'bar', | ||
fontFamily: 'Junction Light', | ||
active: { | ||
allowMultipleDataPointsSelection: true, | ||
}, | ||
events: { | ||
dataPointSelection: function (event, chartContext, config) { | ||
page = data[config.selectedDataPoints]; | ||
parent.location = '/tag/' + page; | ||
} | ||
} | ||
}, | ||
plotOptions: { | ||
bar: { | ||
horizontal: true, | ||
} | ||
}, | ||
dataLabels: { | ||
enabled: false | ||
}, | ||
series: [{ | ||
name: 'Tag count', | ||
data: values | ||
}], | ||
xaxis: { | ||
categories: data | ||
} | ||
}; | ||
var chart_tag = new ApexCharts(document.querySelector("#moderator_tag"), options); | ||
chart_tag.render(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use
.exists?
instead of .present?
reference https://semaphoreci.com/blog/2017/03/14/faster-rails-how-to-check-if-a-record-exists.html also sidenote: @cesswairimu @jywarren should we do a refactoring for this in the app too?