Skip to content

Commit

Permalink
Merge pull request #19 from realstorypro/exclude-tags
Browse files Browse the repository at this point in the history
Adding ability to exclude tags & updating the ui
  • Loading branch information
Leonid Medovyy committed May 6, 2023
2 parents 6ce712e + 0442ffa commit 107f4d8
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 24 deletions.
1 change: 1 addition & 0 deletions app/controllers/feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ class FeedsController < ApplicationController

def index
@feeds = Feed.all.order(id: :desc).page params[:page]
@total_feeds = Feed.all.count
end
end
1 change: 1 addition & 0 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class StoriesController < ApplicationController
include RestrictedAccess
def index
@stories = Story.all.order(id: :desc).page params[:page]
@total_stories = Story.all.count
end

def show
Expand Down
1 change: 1 addition & 0 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ class TagsController < ApplicationController
def index
grouped_tags = Tag.joins(:taggings).group(:name).order('count_id DESC').count(:id)
@tags = Kaminari.paginate_array(grouped_tags.to_a).page(params[:page])
@total_tags = Tag.all.count
end
end
3 changes: 3 additions & 0 deletions app/jobs/assemble_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ def perform(*args)
# Process SubTopics into Stories
Stories::ProcessSubtopicsJob.perform_now

# Create Stemmed Stories
Stories::ProcessStoryStemsJob.perform_now

end
end
2 changes: 0 additions & 2 deletions app/jobs/feed_items/process_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ class ProcessJob < ApplicationJob
queue_as :default

def perform(*_args)
# feeds = Feed.where("created_at >= ? AND created_at <= ?",
# Time.zone.now.utc.beginning_of_day, Time.zone.now.utc.end_of_day)
feeds = Feed.where(processed: false)

feeds.each do |feed|
Expand Down
11 changes: 8 additions & 3 deletions app/jobs/stories/create_stories_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ def process_sub_topic(sub_topic:)
.group(:name).count(:id)
sorted_unprocessed_tag_frequency = unprocessed_tag_frequency.sort { |a, b| b.last <=> a.last }

# Removing excluded tags
if Settings.excluded_tags.present?
entries_to_remove = Settings.excluded_tags
sorted_unprocessed_tag_frequency.delete_if { |entry| entries_to_remove.include?(entry[0]) }
end

# too few tags don't do anything
return if sorted_unprocessed_tag_frequency.size < MINIMUM_TAG_ARRAY_SIZE
return if sorted_unprocessed_tag_frequency[1][1] < sub_topic.min_tags_for_story
return if sorted_unprocessed_tag_frequency[0][1] < sub_topic.min_tags_for_story

story_tag_name = sorted_unprocessed_tag_frequency[1][0]
story_tag_frequency = sorted_unprocessed_tag_frequency[1][1]
story_tag_name = sorted_unprocessed_tag_frequency[0][0]
story_tag_frequency = sorted_unprocessed_tag_frequency[0][1]
tag = Tag.find_by(name: story_tag_name)

available_feed_items = FeedItem.joins(taggings: :tag)
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/stories/make_stem_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def perform(story:)
SYSTEM_ROLE

question = <<~QUESTION
- You have received the following as a news brief about `#{story.tag.name}`.
- You have received the following as a news brief about `#{story.sub_topic.name}` and `#{story.tag.name}`.
- It is your job to write an article consisting of 6 sections, each section has the following format:
```
+ header
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Stories
class ProcessStoriesJob < ApplicationJob
class ProcessStoryStemsJob < ApplicationJob
queue_as :default

def perform(*args)
Expand Down
2 changes: 1 addition & 1 deletion app/views/feeds/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

=r ux.h2 'center aligned !font-mono'
| Feeds
=r ux.label text: @feeds.count, class: 'circular !bg-orange-700 !text-white'
=r ux.label text: @total_feeds, class: 'circular !bg-orange-700 !text-white'

=r ux.div 'text-center'
= paginate @feeds
Expand Down
1 change: 0 additions & 1 deletion app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ html lang="en"
meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"

= vite_stylesheet_tag 'admin.sass', 'data-turbo-track': 'reload'
/ = stylesheet_link_tag *'https://fonts.googleapis.com/css2?family=Space Grotesk:wght@400;600;700&display=swap', media: 'none', onload: "if(media!='all')media='all'"
= vite_javascript_tag 'admin', 'data-turbo-track': 'reload'
= csrf_meta_tags
= canonical_tag
Expand Down
2 changes: 1 addition & 1 deletion app/views/stories/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

=r ux.h2 'center aligned !font-mono'
| Stories
=r ux.label text: @stories.count, class: 'circular !bg-blue-700 !text-white'
=r ux.label text: @total_stories, class: 'circular !bg-blue-700 !text-white'

=r ux.div 'text-center'
= paginate @stories
Expand Down
2 changes: 1 addition & 1 deletion app/views/tags/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

=r ux.h2 'center aligned !font-mono'
| Tags
=r ux.label text: @tags.count, class: 'circular !bg-purple-700 !text-white'
=r ux.label text: @total_tags, class: 'circular !bg-purple-700 !text-white'

=r ux.div 'text-center'
= paginate @tags
Expand Down
26 changes: 13 additions & 13 deletions blueprints/topics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@ topics:
sub_topics:
- name: Action
stream_id: feed/https://feedly.com/f/alert/84708e45-f057-41bb-87e8-99df56d358e9
min_tags_for_story: 3
min_tags_for_story: 2
- name: Adventure
stream_id: feed/https://feedly.com/f/alert/627b968a-3473-4d4f-ade7-321976996695
min_tags_for_story: 3
min_tags_for_story: 2
- name: Puzzle
stream_id: feed/https://feedly.com/f/alert/55b44c1b-b0a7-47b0-8100-67c0cd9a914e
min_tags_for_story: 3
min_tags_for_story: 2
- name: Role Playing
stream_id: feed/https://feedly.com/f/alert/45bf01b0-96ad-4d26-a17a-9866aa0fb92d
min_tags_for_story: 3
min_tags_for_story: 2
- name: Simulation
stream_id: feed/https://feedly.com/f/alert/05785e57-c996-4d63-b6e9-158ebaf106fd
min_tags_for_story: 3
min_tags_for_story: 2
- name: Strategy
stream_id: feed/https://feedly.com/f/alert/575682bc-bd36-46ab-bd33-90a40357e93c
min_tags_for_story: 3
min_tags_for_story: 2
- name: Team Sports
maximum_topics: 6
sub_topics:
- name: American Football
stream_id: feed/https://feedly.com/f/alert/c84be72f-892f-48d0-9ec6-a9ced03f6065
min_tags_for_story: 3
min_tags_for_story: 2
- name: Soccer
stream_id: feed/https://feedly.com/f/alert/f38eef1e-1feb-4899-b164-e401a1ee463a
min_tags_for_story: 3
min_tags_for_story: 2
- name: Basketball
stream_id: feed/https://feedly.com/f/alert/aa390cd3-71d3-4793-8265-3971122b802b
min_tags_for_story: 3
min_tags_for_story: 2
- name: Baseball
stream_id: feed/https://feedly.com/f/alert/d6c2b0d8-67cd-4a7c-910a-dcde54a4ebe7
min_tags_for_story: 3
min_tags_for_story: 2
- name: Cricket
stream_id: feed/https://feedly.com/f/alert/383f7f0a-c212-4d39-9381-09d4712114e3
min_tags_for_story: 3
min_tags_for_story: 2
- name: Rugby
stream_id: feed/https://feedly.com/f/alert/80849568-f621-4c53-ad75-02b1215a284e
min_tags_for_story: 3
min_tags_for_story: 2
- name: Volleyball
stream_id: feed/https://feedly.com/f/alert/df0497a0-23e9-45a8-869a-951ef3ec8022
min_tags_for_story: 3
min_tags_for_story: 2
5 changes: 5 additions & 0 deletions blueprints/tuning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
excluded_tags:
- Games
- Video Games
- Sports
- Sport
16 changes: 16 additions & 0 deletions config/initializers/01_config_bootloader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# find all files in core directory
Dir.chdir('blueprints')
files = Dir['**/**']

# select only YML files
files.select! { |entry| entry.include?('yml') == true }

# add all file as a source to the settings
files.each { |entry| Settings.add_source!(Rails.root.join('blueprints', entry).to_s) }

Settings.reload!

# Backup a directory
Dir.chdir('..')
12 changes: 12 additions & 0 deletions lib/tasks/stories.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace :stories do
desc 'Resetting stories'
task reset: :environment do
puts 'resetting stories'

# Feed.update_all(processed: false)
FeedItem.update_all(processed: false)
StoryTag.delete_all
Assignment.delete_all
Story.delete_all
end
end

0 comments on commit 107f4d8

Please sign in to comment.