-
Notifications
You must be signed in to change notification settings - Fork 0
🔖Version 0.1.0 #6
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
Open
ThierryO
wants to merge
17
commits into
main
Choose a base branch
from
0.1.0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7d4ddc8
🔖 Bump package version
ThierryO dff057b
✨ Split surveys in groups when importing the observations
ThierryO 52789f7
✨ Add a function to test for unlikely status distribution
ThierryO dbf566e
✨ Add edge_distribution()
ThierryO 45bfc24
✨ Add unlikely_edge_distribution()
ThierryO addeb1d
✨ Add user and region when importing observations
ThierryO 2c2efb4
🐛 Keep singletons when splitting surveys into groups
ThierryO e5532a8
✨ Add function to detect surveys with an unlikely large area
ThierryO fad65f6
🎨 Rename p field to value in unlikely table
ThierryO 7faa197
✨ Add get_total()
ThierryO ff9dbcc
✨ Add get_unlikely_summary()
ThierryO 09f4292
✨ Add get_unlikely_observation()
ThierryO a19a794
💚 Fix checklist issues
ThierryO 82ae7fe
✨ Get_cluster() ignores unlikely surveys
ThierryO 99e69ca
📝 Update NEWS
ThierryO 1056ed4
👷 Use latest checklist version
ThierryO a95a46c
Apply suggestions from code review
ThierryO 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
### GNU GENERAL PUBLIC LICENSE | ||
# GNU GENERAL PUBLIC LICENSE | ||
|
||
Version 3, 29 June 2007 | ||
|
||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,40 @@ | ||
#' @title Edge distribution | ||
#' @description | ||
#' This function return the length of the edges of the Delaunay triangulation | ||
ThierryO marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
#' per survey. | ||
#' The function returns only edges with length smaller than twice `max_dist`. | ||
#' @inheritParams import_observations | ||
#' @importFrom assertthat assert_that is.number noNA | ||
#' @importFrom deldir deldir | ||
#' @importFrom RSQLite dbGetQuery | ||
#' @export | ||
edge_distribution <- function(conn, max_dist = 336) { | ||
assert_that( | ||
inherits(conn, "SQLiteConnection"), | ||
is.number(max_dist), noNA(max_dist), max_dist > 0 | ||
) | ||
"SELECT survey, x, y FROM observation" |> | ||
dbGetQuery(conn = conn) -> observations | ||
table(observations$survey) |> | ||
as.data.frame() -> n_survey | ||
n_survey[n_survey$Freq > 1, ] |> | ||
merge(x = observations, by.y = "Var1", by.x = "survey") -> observations | ||
edges <- data.frame(survey = integer(0), length = numeric(0)) | ||
for (i in unique(observations$survey)) { | ||
candidate <- which(observations$survey == i) | ||
dd <- deldir( | ||
x = rnorm(length(candidate), mean = observations$x[candidate], sd = 0.01), | ||
y = rnorm(length(candidate), mean = observations$y[candidate], sd = 0.01), | ||
id = observations$id[candidate] | ||
) | ||
extra <- data.frame( | ||
survey = i, | ||
length = sqrt( | ||
(dd$delsgs$x2 - dd$delsgs$x1) ^ 2 + (dd$delsgs$y2 - dd$delsgs$y1) ^ 2 | ||
) | ||
) | ||
extra[extra$length <= 2 * max_dist, ] |> | ||
rbind(edges) -> edges | ||
} | ||
return(edges) | ||
} |
This file contains hidden or 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 hidden or 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,52 @@ | ||
#' Get the total number of individuals per region | ||
#' Returns the sum of `value` per region. | ||
#' Clusters spanning more than one region get each a fraction of `value` based | ||
#' on the number of observations of the cluster in a region divided by the total | ||
#' number of observations in the cluster. | ||
#' @inheritParams import_observations | ||
#' @param value A string representing the value per cluster to be calculated. | ||
#' Default is `"IIF(max_status >= 2, 1, iif(n_total > 1, 0.5, 0))"`. | ||
#' Available variables are | ||
#' - `max_status`: the highest status of a cluster. | ||
#' - `n_total`: the total number of observations per cluster | ||
#' - `n_region`: the number of observations in a cluster from the same region. | ||
#' @export | ||
#' @importFrom assertthat assert_that is.string noNA | ||
#' @importFrom RSQLite dbGetQuery | ||
get_total <- function( | ||
conn, value = "IIF(max_status >= 2, 1, iif(n_total > 1, 0.5, 0))" | ||
) { | ||
assert_that( | ||
inherits(conn, "SQLiteConnection"), is.string(value), noNA(value) | ||
) | ||
sprintf( | ||
"WITH cte_obs AS ( | ||
SELECT o.region, o.cluster, o.status | ||
FROM observation AS o | ||
LEFT JOIN unlikely AS u ON o.survey = u.survey | ||
WHERE u.value IS NULL | ||
), | ||
cte_region AS ( | ||
SELECT cluster, region, COUNT(cluster) AS n_region | ||
FROM cte_obs | ||
WHERE region IS NOT NULL | ||
GROUP BY cluster, region | ||
), | ||
cte_cluster AS ( | ||
SELECT cluster, MAX(status) AS max_status, COUNT(status) AS n_total | ||
FROM cte_obs | ||
GROUP BY cluster | ||
), | ||
cte AS ( | ||
SELECT | ||
r.region, c.cluster, 1.0 * r.n_region / c.n_total AS fraction, | ||
%s AS value | ||
FROM cte_region AS r | ||
INNER JOIN cte_cluster AS c ON r.cluster = c.cluster | ||
) | ||
|
||
SELECT region, SUM(value * fraction) AS individuals FROM cte GROUP BY region", | ||
value | ||
) |> | ||
dbGetQuery(conn = conn) | ||
} |
This file contains hidden or 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,39 @@ | ||
#' Get an overview of the unlikely reasons for each survey and region | ||
ThierryO marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
#' @inheritParams import_observations | ||
#' @export | ||
#' @importFrom assertthat assert_that | ||
#' @importFrom RSQLite dbGetQuery | ||
get_unlikely_summary <- function(conn = conn) { | ||
assert_that(inherits(conn, "SQLiteConnection")) | ||
"WITH cte AS ( | ||
SELECT survey, region, COUNT(id) n | ||
FROM observation | ||
WHERE region IS NOT NULL | ||
GROUP BY survey, region | ||
), | ||
cte_survey AS ( | ||
SELECT survey, region FROM cte GROUP BY survey HAVING n = MAX(n) | ||
) | ||
SELECT c.region, c.survey, u.reason | ||
FROM cte_survey AS c | ||
INNER JOIN unlikely AS u ON c.survey = u.survey | ||
ORDER BY c.region, c.survey" |> | ||
dbGetQuery(conn = conn) | ||
} | ||
|
||
#' Get the unlikely observations | ||
#' @inheritParams import_observations | ||
#' @inheritParams sf::st_as_sf | ||
#' @export | ||
#' @importFrom assertthat assert_that | ||
#' @importFrom RSQLite dbGetQuery | ||
#' @importFrom sf st_as_sf | ||
get_unlikely_observation <- function(conn, crs = 31370) { | ||
assert_that(inherits(conn, "SQLiteConnection")) | ||
"SELECT o.id, o.x, o.y, o.status, o.region, o.survey, s.original, s.user | ||
FROM observation AS o | ||
INNER JOIN unlikely AS u ON o.survey = u.survey | ||
INNER JOIN survey AS s on o.survey = s.id" |> | ||
dbGetQuery(conn = conn) |> | ||
st_as_sf(coords = c("x", "y"), crs = crs) | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.