Skip to content
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

FGS Database Features #9

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
6cba088
Merge metadata
callawaywilson Jul 31, 2024
20cc02c
Removed Trachoma references
callawaywilson Jul 31, 2024
0f24e30
Image sets implementations
callawaywilson Aug 1, 2024
fc3ab1f
Polymorphic grading sets
callawaywilson Aug 1, 2024
24ed191
Removed typo
callawaywilson Aug 1, 2024
a18d3e4
Added JS grading
callawaywilson Aug 1, 2024
6df4ddf
FGS Grading app
callawaywilson Aug 6, 2024
ba2c967
Merge branch 'master' into fgsdb
callawaywilson Aug 6, 2024
4975e4a
Questionnaire
callawaywilson Aug 15, 2024
5cb56d9
Metadata downloads
callawaywilson Aug 16, 2024
d011c77
Forward/back images
callawaywilson Aug 16, 2024
921863d
JS Nav Away prompt
callawaywilson Aug 16, 2024
708e1b7
Expanded multi options download
callawaywilson Aug 16, 2024
e09205e
Rails update
callawaywilson Aug 19, 2024
87e887a
Rails update
callawaywilson Aug 19, 2024
67152a1
Rolled back
callawaywilson Aug 19, 2024
14b5d88
Rolled back
callawaywilson Aug 19, 2024
499d7b9
Updated names
callawaywilson Aug 19, 2024
ec1f49d
Fixed issue with image folder saving
callawaywilson Aug 21, 2024
79a511b
Filename anywhere in metadata
callawaywilson Aug 21, 2024
4ad232b
Fixed navaway
callawaywilson Aug 21, 2024
87125c4
Fixed scroll behavior
callawaywilson Aug 21, 2024
7afa1f6
Updated grading app
callawaywilson Aug 21, 2024
9cb547b
Grading data downloads
callawaywilson Aug 23, 2024
5329ad0
Fixed metadata download
callawaywilson Aug 27, 2024
1c7b305
Fixed issue with image sets search
callawaywilson Aug 27, 2024
cfb56b1
Metadata search
callawaywilson Aug 27, 2024
5c26193
Refactored out Image::SIZES
callawaywilson Aug 27, 2024
9266d3c
Vips image processing
callawaywilson Aug 27, 2024
aa935a1
Metadata upload updates
callawaywilson Sep 9, 2024
02689d9
Download Image Set grading data from Images
callawaywilson Sep 11, 2024
d000adc
Download Image Set UI
callawaywilson Sep 11, 2024
efc1569
Better image vs. image set differentiation
callawaywilson Sep 12, 2024
08d0028
redirect home to dashboard
callawaywilson Sep 12, 2024
b77b9e6
Added ferrum
callawaywilson Oct 8, 2024
5bc32c4
Added ferrum
callawaywilson Oct 8, 2024
9e0bca1
Added image sync
callawaywilson Oct 13, 2024
4ead275
Credentials for sync from env
callawaywilson Oct 13, 2024
a1a9f64
Sync days param
callawaywilson Oct 14, 2024
8ff7ae7
PID participant id
callawaywilson Oct 15, 2024
7e78f81
Sync metadata updates
callawaywilson Oct 15, 2024
4c7c8d8
More sync logging
callawaywilson Oct 16, 2024
c432b19
More sync logging
callawaywilson Oct 16, 2024
09a07a0
More sync logging
callawaywilson Oct 16, 2024
4f674a2
More sync logging
callawaywilson Oct 16, 2024
6456ae8
Restart browser when needed
callawaywilson Oct 16, 2024
a9c9a3e
Browser reset
callawaywilson Oct 17, 2024
450b501
Browser reset
callawaywilson Oct 17, 2024
fe8a702
Browser reset
callawaywilson Oct 18, 2024
e87bd71
Browser reset
callawaywilson Oct 18, 2024
7547895
Browser reset
callawaywilson Oct 18, 2024
a3ef83f
Browser reset
callawaywilson Oct 18, 2024
fa4526f
Browser reset
callawaywilson Oct 18, 2024
f2977ce
Browser reset
callawaywilson Oct 18, 2024
a5f0314
Redis config
callawaywilson Oct 19, 2024
c785f90
Sidekiq config
callawaywilson Oct 19, 2024
67538fd
Merge master
callawaywilson Oct 31, 2024
9aa1b7e
Merge master
callawaywilson Oct 31, 2024
7a665ab
Sync for pid-date
callawaywilson Nov 1, 2024
ba124c2
Sync updated
callawaywilson Nov 1, 2024
bd0b531
Sync updated
callawaywilson Nov 1, 2024
c25d026
Nav fix
callawaywilson Nov 4, 2024
0a55bff
Dependent image set images delete
callawaywilson Nov 4, 2024
fb7d8f2
Dependent image set images delete
callawaywilson Nov 4, 2024
e9c279a
Smaller sync reset size
callawaywilson Nov 4, 2024
4774697
Removed old docs link
callawaywilson Nov 14, 2024
38fc363
Protect locked metadata keys
callawaywilson Nov 21, 2024
df50fe9
Sync clinician name
callawaywilson Nov 21, 2024
17e7883
Sync in clinician names
callawaywilson Nov 21, 2024
ccdd249
More max synced for clinician names
callawaywilson Nov 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ gem 'exifr', '~> 1.3', '>= 1.3.9'

gem "aws-sdk-s3", require: false

# Vessel for webcrawling
gem "ferrum"

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ GEM
erubi (1.10.0)
execjs (2.8.1)
exifr (1.3.9)
ferrum (0.15)
addressable (~> 2.5)
concurrent-ruby (~> 1.1)
webrick (~> 1.7)
websocket-driver (~> 0.7)
ffi (1.15.4)
globalid (1.0.0)
activesupport (>= 5.0)
Expand Down Expand Up @@ -234,6 +239,7 @@ GEM
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
webrick (1.8.2)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand All @@ -254,6 +260,7 @@ DEPENDENCIES
byebug
capybara (>= 3.26)
exifr (~> 1.3, >= 1.3.9)
ferrum
image_processing (~> 1.12, >= 1.12.2)
jbuilder (~> 2.7)
listen (~> 3.3)
Expand Down
16 changes: 16 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ img.flipped {
transform: scaleX(-1);
}

.GradeableImages {
.ImageThumbnail {
cursor: pointer;
}
.ImageFill {
width: 100%;
height: 100%;
}
.ImageFullscreen {
width: 100%;
}
}


// Style overrides
body {
Expand Down Expand Up @@ -72,3 +85,6 @@ body {
text-decoration: none;
}
}
.list-unstyled {
margin-bottom: 0;
}
12 changes: 3 additions & 9 deletions app/controllers/grading_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class GradingController < ApplicationController

skip_before_action :verify_authenticity_token, only: [:grade]

def index
@user_grading_set = current_user.user_grading_set_for(params[:grading_set_id])
if !@user_grading_set.image_complete?
Expand Down Expand Up @@ -34,15 +36,7 @@ def grade
)
end
@user_grading_set_image.flipped = params[:flipped] == '1'
@user_grading_set_image.grading_data = params.permit(grading_data: [
:photo_quality,
:is_everted,
:tf_grade,
:ti_grade,
:ts_grade,
:upper_lid_tt_grade,
:lower_lid_tt_grade
])['grading_data']
@user_grading_set_image.grading_data = JSON.parse(params[:grading_data])
@user_grading_set_image.save!
flash.notice = "#{@user_grading_set.grading_set.name} image grade saved!"
redirect_to action: 'index', grading_set_id: params[:grading_set_id]
Expand Down
18 changes: 8 additions & 10 deletions app/controllers/grading_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ def create
end

def data
@grading_set = GradingSet.find params[:id]
# @grading_set = GradingSet.find params[:id]
stream_csv_response filename: 'report.csv',
enumerator: @grading_set.csv_enumerator
enumerator: UserGradingSetImage.data_csv_enumerator({
grading_sets: {id: params[:id]}
})
end

def destroy
Expand Down Expand Up @@ -96,16 +98,12 @@ def removeuser
end

def removeimage
@grading_set = GradingSet.find params[:id]
@image = Image.find params[:image_id]
@grading_set_image = GradingSetImage.where({
image: @image,
grading_set: @grading_set
}).first
@grading_set_image = GradingSetImage.find params[:grading_set_image_id]
name = @grading_set_image.gradeable.name
if @grading_set_image && @grading_set_image.destroy
flash.notice = "#{@image.filename} removed from grading set"
flash.notice = "#{name} removed from grading set"
else
flash.alert = "Unable to remove #{@image.filename} from grading set"
flash.alert = "Unable to remove #{name} from grading set"
end
redirect_to action: 'show'
end
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ class HomeController < ApplicationController
skip_before_action :require_login

def index
if current_user
@user_grading_sets = current_user.user_grading_sets
.order('created_at desc')
.limit(3)
end
redirect_to controller: 'dashboard'
# if current_user
# @user_grading_sets = current_user.user_grading_sets
# .order('created_at desc')
# .limit(3)
# end
end

end
112 changes: 112 additions & 0 deletions app/controllers/image_sets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
class ImageSetsController < ApplicationController
include CsvStreamable

before_action :require_image_viewer, only: [:index, :show]
before_action :require_admin, only: [:addtogradingset]

skip_before_action :verify_authenticity_token, only: [:addtogradingset, :gradingdata, :metadata]

def index
@pagesize = 50
@limit = (params[:limit] || @pagesize).to_i
@offset = (params[:offset] || 0).to_i
@image_sets = search_image_sets
.includes(:image_set_images, :grading_sets)
.limit(@limit).offset(@offset)
@image_sets_count = search_image_sets.count
@image_sources = ImageSource.active.order('name desc')
@metadata_keys = ImageSet.all_metadata_keys
respond_to do |format|
format.html
format.json { render json: {images: @images} }
end

end

def show
@image_set = ImageSet.find params[:id]
end

def new

end

def update

end

def create

end

def destroy

end

def set_images

end

def download

end

def metadata
stream_csv_response filename: 'metadata.csv',
enumerator: ImageSet.csv_metadata_enumerator(search_image_set_ids)
end


def addtogradingset
@grading_set = GradingSet.find params[:grading_set_id]
unless @grading_set
return redirect_to({ action: 'index' }, flash: { error: "No such grading set" })
end
if params[:image_set_id_all] == 'all'
@image_set_ids = search_image_sets.select(:id).map(&:id)
@count = GradingSetImage.upsert_all(@image_set_ids.map {|image_set_id|
{
gradeable_id: image_set_id,
gradeable_type: 'ImageSet',
grading_set_id: @grading_set.id,
created_at: Time.zone.now,
updated_at: Time.zone.now
}
}, unique_by: [:grading_set_id, :gradeable_id], returning: [:id]).count
else
@count = GradingSetImage.upsert_all(params[:image_set_ids].map {|image_set_id|
{
gradeable_id: image_set_id,
gradeable_type: 'ImageSet',
grading_set_id: @grading_set.id,
created_at: Time.zone.now,
updated_at: Time.zone.now
}
}, unique_by: [:grading_set_id, :gradeable_id], returning: [:id]).count
end
return redirect_to({ action: 'index' }, flash: {
success: "Successfully added #{@count} image sets to #{@grading_set.name}"
})
end

def gradingdata
stream_csv_response filename: 'image_set_gradingdata.csv',
enumerator: UserGradingSetImage.data_csv_enumerator({
image_sets: params
})
end

private

def image_set_params
params.require(:image_set).permit(:name, :image_source_id, :metadata)
end

def search_image_sets
ImageSet.search(params)
end

def search_image_set_ids
search_image_sets.select(:id).map(&:id)
end
end
7 changes: 6 additions & 1 deletion app/controllers/image_sources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ def image_urls
private

def image_source_params
params.require(:image_source).permit(:name, :active)
params.require(:image_source).permit(
:name,
:active,
:create_image_sets,
:create_image_sets_metadata_field
)
end

def metadata_params
Expand Down
69 changes: 21 additions & 48 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ class ImagesController < ApplicationController
before_action :require_admin, only: [:addtogradingset]

skip_before_action :verify_authenticity_token,
only: [:addtogradingset, :metadata, :exif_data]
only: [:addtogradingset, :metadata, :exif_data, :gradingdata]

skip_forgery_protection only: [:index]

def index
@pagesize = 50
@limit = (params[:limit] || @pagesize).to_i
@offset = (params[:offset] || 0).to_i
@images = search_images.limit(@limit).offset(@offset)
@images_count = search_images.count
@images = Image.search(params).limit(@limit).offset(@offset)
@images_count = Image.search(params).count
@image_sources = ImageSource.active.order('name desc')
@metadata_keys = Image.all_metadata_keys
respond_to do |format|
Expand Down Expand Up @@ -61,24 +61,26 @@ def addtogradingset
return redirect_to({ action: 'index' }, flash: { error: "No such grading set" })
end
if params[:image_id_all] == 'all'
@image_ids = search_images.select(:id).map(&:id)
@image_ids = Image.search(params).select(:id).map(&:id)
@count = GradingSetImage.upsert_all(@image_ids.map {|image_id|
{
image_id: image_id,
gradeable_id: image_id,
gradeable_type: 'Image',
grading_set_id: @grading_set.id,
created_at: Time.zone.now,
updated_at: Time.zone.now
}
}, unique_by: [:grading_set_id, :image_id], returning: [:id]).count
}, unique_by: [:grading_set_id, :gradeable_id], returning: [:id]).count
else
@count = GradingSetImage.upsert_all(params[:image_ids].map {|image_id|
{
image_id: image_id,
gradeable_id: image_id,
gradeable_type: 'Image',
grading_set_id: @grading_set.id,
created_at: Time.zone.now,
updated_at: Time.zone.now
}
}, unique_by: [:grading_set_id, :image_id], returning: [:id]).count
}, unique_by: [:grading_set_id, :gradeable_id], returning: [:id]).count
end
return redirect_to({ action: 'index' }, flash: {
success: "Successfully added #{@count} images to #{@grading_set.name}"
Expand All @@ -87,19 +89,26 @@ def addtogradingset

def metadata
stream_csv_response filename: 'metadata.csv',
enumerator: Image.csv_metadata_enumerator(search_image_ids)
enumerator: Image.csv_metadata_enumerator(search_image_ids(params))
end

def exif_data
stream_csv_response filename: 'exif_data.csv',
enumerator: Image.csv_exif_data_enumerator(search_image_ids)
enumerator: Image.csv_exif_data_enumerator(search_image_ids(params))
end

def download
@image_sources = ImageSource.active.order("name desc").all
@image_source_id = params[:image_source_id]
end

def gradingdata
stream_csv_response filename: 'image_gradingdata.csv',
enumerator: UserGradingSetImage.data_csv_enumerator({
images: params
})
end

# def update
# @image = Image.find params[:id]
# respond_to do |format|
Expand All @@ -122,44 +131,8 @@ def new_image_params
)
end

def search_images
wheres = ["1=1"]
wheres_params = {}
joins = []
unless params[:metadata_key].blank?
safe_key = params[:metadata_key].gsub("'", "") # remove single quotes
wheres << "images.metadata->>'#{safe_key}' like :metadata_value"
wheres_params[:metadata_value] = "%#{params[:metadata_value]}%"
end
unless params[:image_ids].blank?
wheres << 'images.id in (:image_ids)'
wheres_params[:image_ids] = params[:image_ids]
end
unless params[:filename].blank?
wheres << 'filename ilike :filename'
wheres_params[:filename] = "%#{params[:filename]}%"
end
unless params[:image_source_id].blank?
wheres << 'image_source_id = :image_source_id'
wheres_params[:image_source_id] = params[:image_source_id]
end
unless params[:image_source].blank?
joins << :image_source
wheres << 'image_sources.name ilike :image_source'
wheres_params[:image_source] = "%#{params[:image_source]}%"
end
unless params[:grading_set].blank?
joins << :grading_sets
wheres << 'grading_sets.name ilike :grading_set'
wheres_params[:grading_set] = "%#{params[:grading_set]}%"
end
Image.active.joins(joins)
.order("images.filename asc")
.where(wheres.join(" and "), wheres_params)
end

def search_image_ids
search_images.select(:id).map(&:id)
def search_image_ids(params)
Image.search(params).select(:id).map(&:id)
end

end
Loading